- 浏览: 238421 次
- 性别:
- 来自: 济南
文章分类
- 全部博客 (205)
- jQuery (27)
- Flash AS3.0 (0)
- Html5+CSS3 (12)
- C# .Net (19)
- Xml XPath XSLT (5)
- Sql (3)
- JavaScript (20)
- struts2 (23)
- hibernate (24)
- spring (11)
- j2ee (16)
- jsp/java (11)
- 设计模式 (5)
- json (3)
- Java.IO (7)
- Java.Util (7)
- android (8)
- WebService (10)
- MyEclipse SVN (3)
- servlet (1)
- Exception (3)
- 自我学习 (2)
- UML (2)
- java泛型 (1)
- Lucene (7)
- HtmlParser (2)
- 概念理解 (3)
- 正则表达式 (1)
- EMail (1)
最新评论
-
hanmiao:
没用,干巴巴的壹堆代码,没明白到底区别在哪里。
List Set Map 区别! -
e421083458:
偶来过了!
C#单向链表的实现
package com.bjsxt.hibernate.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
@Entity
public class Husband {
private int id;
private String name;
private Wife wife;
@Id
@GeneratedValue
public int getId() {
return id;
}
public String getName() {
return name;
}
@OneToOne
@JoinColumn(name="wifeId")
public Wife getWife() {
return wife;
}
public void setId(int id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setWife(Wife wife) {
this.wife = wife;
}
}
package com.bjsxt.hibernate.model;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
public class Student {
private int id;
private int age;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- 设置数据库连接 -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/hibernate</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<!-- 在真正的项目开中一般不用hinernate自带的连接池 -->
<!-- <property name="connection.pool_size">1</property> -->
<!-- SQL 方言 -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management
<property name="current_session_context_class">thread</property> -->
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- 是否需要打印出来sql语句 -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<!-- <mapping resource="com/bjsxt/hibernate/model/Student.hbm.xml"/> -->
<mapping class="com.bjsxt.hibernate.model.Wife"/>
<mapping class="com.bjsxt.hibernate.model.Husband"/>
</session-factory>
</hibernate-configuration>
生成表:
new SchemaExport(new AnnotationConfiguration().configure()).create(false, true);
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
@Entity
public class Husband {
private int id;
private String name;
private Wife wife;
@Id
@GeneratedValue
public int getId() {
return id;
}
public String getName() {
return name;
}
@OneToOne
@JoinColumn(name="wifeId")
public Wife getWife() {
return wife;
}
public void setId(int id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setWife(Wife wife) {
this.wife = wife;
}
}
package com.bjsxt.hibernate.model;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
public class Student {
private int id;
private int age;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- 设置数据库连接 -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/hibernate</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<!-- 在真正的项目开中一般不用hinernate自带的连接池 -->
<!-- <property name="connection.pool_size">1</property> -->
<!-- SQL 方言 -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management
<property name="current_session_context_class">thread</property> -->
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- 是否需要打印出来sql语句 -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<!-- <mapping resource="com/bjsxt/hibernate/model/Student.hbm.xml"/> -->
<mapping class="com.bjsxt.hibernate.model.Wife"/>
<mapping class="com.bjsxt.hibernate.model.Husband"/>
</session-factory>
</hibernate-configuration>
生成表:
new SchemaExport(new AnnotationConfiguration().configure()).create(false, true);
发表评论
-
java的枚举的定义和使用
2012-01-12 23:29 1127public emun EmunName { w ... -
常用SQL语句
2011-12-31 11:33 621MySql分组查询语句: from Share as s ... -
hibernate对映射xml的一对多的双向关联详解
2011-12-18 00:15 840<?xml version="1.0" ... -
getHibernateTemplate().execute(new HibernateCallback())方法
2011-12-14 09:43 4201. HibernateCallback是一个 ... -
Java企业级开发SSH三大框架的Jar包
2011-12-06 18:39 911123 -
struts spring hibernate配置文件
2011-10-24 21:24 909ApplicationContext ctx = new Cl ... -
Annotation的关联关系
2011-10-19 23:22 647一对一、一对多、多对多、组合映射、主键关系 的单向和双向 ... -
hibernate 名词解释
2011-10-18 23:20 721JPA是一个标准(接口),hibernate只是一个实现 先有 ... -
Junit测试文件
2011-10-18 22:19 790package com.bjsxt.hibernate; ... -
log4j.properties
2011-10-18 22:00 683### direct log messages to stdo ... -
Hibernate的Hql
2011-09-23 21:58 1083Hibernate 查询语言 NativeSQL(不执行跨平台 ... -
Hibernate级联操作
2011-09-23 00:15 846package com.secn.user; import ... -
Hibernate关系映射
2011-09-22 22:14 621关系映射: 对象之间的关系 一对一(单向和双向) Annont ... -
Hibenrate一对多和多对多
2011-09-20 23:18 302... -
Hibernate联合主键
2011-09-20 22:35 746package com.bjsxt.hibernate; i ... -
Hibernate一对一的关联关系
2011-09-20 22:30 642... -
Load()和Get()的区别和update用法
2011-09-20 20:03 933Load(Teacher.Class,1); Teacher. ... -
Configuration_SessionFactory_GetCurrentSession_OpenSession以及Hibernate中的三种状态
2011-09-19 21:55 726SessionFactory sf = new Configu ... -
常用的hiberante中xml的ID生成策略
2011-09-19 21:09 1104hiberante的xml生成策略: 策略一般是指:1. 可以 ... -
hibernate Annotation版本持久化实体类
2011-09-18 01:16 704package com.bjsxt.hibernate; ...
相关推荐
NULL 博文链接:https://xhfei.iteye.com/blog/691322
一个完整的工程,主要功能为:spring+hbernate对clob、blob字段的处理 包括:数据脚本、典型的SSH框架处理,以及spring、hibernate数据批量保存等功能源码、所用到的lib包 数据环境为:oracle 10G 开发:Mycelipse5.1...
毕业设计spring+struts2+hbernate博客系统源码+部署文档+论文
struts + DAO + Hbernate的脚本
Hbernate的有源码的文件,可以帮助你学好hbernat
自己昨晚上写的 但是没有加入验证码验证机制 数据库 chat 表名user 字段 id name pass
Spring-HBERNATE Spring -hibernate 与 mysql Spring-HBERNATE
hibernate一份不错的文档,比较适合开始学习或者不熟练hibernate的朋友
集合struts,spring,hibernate三大框架开发,是一个很好的项目实例
一个简单的Struts+Spring+Hibernate的登录模块的代码,含数据库代码和部分简单说明(适合刚接触Struts+Spring+Hibernate框架的开发者); 本例采用myEclipse6.0.1和tomcat6开发,可直接导入myeclipse工程运行...
Hibernate3.2官方中文参考手册PDF,以及Hibernate3.2.jar
最近入职一家公司,使用的 是springmvc框架,之前公司是用的struts2没接触过springmvc,所以这几天学习了一下并写了一个简单的基于注解的demo,数据库用的mysql,就两张表,有外键关联,demo实现了两张表的级联增删...
hibernate hibernate
这个是最新版的hibernate压缩包,2016年传智播客的工具包
用于配置hibernate.cfg.xml和相当的应用,值得看看.........
使用Hibernate的一个完整例子 这是我学习的时候下载的,看着不错 喜欢的可以下载 不要分 但愿能帮到你们
自己用myeclipse开发工具写的一个sh的留言板,包括源代码和jsp页面(jsp页面写的很简单)
1 Database : use mysql5 2 Developer: MyEclipse 5 3 Liberary : J2EE1.4 + JDK1.5 ...参考前辈的经验,非用hibernate生成的,但是并不是说会比生成的好,只是学习一种代码的书写方法和其它一些东西,希望对你有帮助。
struts+hibernate留言板(sh) list分页技术
struts2和Hbernate的一次批量增加所有页面的值和js功能