- 浏览: 148230 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
mengshan007:
material:CHP1\/8\-100\-R8* q 我带 ...
Apache Solr 架设搜索服务器 学习笔记 -
bzlring:
怎么从org json字符串转换为 java对象呢?
Java下的json解析工具 -
adsl123gg2008:
貌似没看懂............
hibernate session 的缓存作用 -
Loulley:
<?xml version="1.0" ...
java生成xml -
pengzheng00:
结果是{"name":"reiz ...
Java下的json解析工具
hibernate.cfg.xml
<?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"> <!-- Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration> <session-factory> <property name="connection.username">root</property> <property name="connection.url">jdbc:mysql://localhost/hibernate</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="myeclipse.connection.profile">mysqlCon</property> <property name="connection.password">123456</property> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="show_sql">true</property> <property name="hibernate.hbm2ddl.auto">update</property> <mapping resource="com/yelang/hibernate/Class.hbm.xml"/> <mapping resource="com/yelang/hibernate/Student.hbm.xml"/> </session-factory> </hibernate-configuration>
HibernateUtils.java
package com.yelang.hibernate; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; public class hibernateUtils { /** * 申明一个 静态的sessionFactory */ private static SessionFactory sf ; /** * 静态块 用来初始化sessionFactory */ static { try { sf = new Configuration().configure().buildSessionFactory(); } catch (HibernateException e) { e.printStackTrace(); } } /** * 反回一个新开的session */ public static Session getSession() { return sf.openSession(); } /** * 关闭Session */ public static void closeSession(Session session) { if(session != null) { if(session.isOpen()) { session.close(); } } } }
class.java
package com.yelang.hibernate; public class Class { private int id; private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
Student.java
package com.yelang.hibernate; public class Student { private int id; private String stuName; private Class classer; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getStuName() { return stuName; } public void setStuName(String stuName) { this.stuName = stuName; } public Class getClasser() { return classer; } public void setClasser(Class classer) { this.classer = classer; } }
Class.hbm.xml
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.yelang.hibernate"> <class name="Class" table="tb_class"> <id name="id"> <generator class="native"/> </id> <property name="name"/> </class> </hibernate-mapping>
Student.hbm.xml
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.yelang.hibernate"> <class name="Student" table="tb_student"> <id name="id"> <generator class="native"/> </id> <property name="stuName"/> <many-to-one name="classer" column="classId" cascade="save-update"/> </class> </hibernate
TestUser.java
package com.yelang.hibernate; import org.hibernate.Session; import junit.framework.TestCase; public class StudentTest extends TestCase { public void testSave() { Session session = null; try{ session = hibernateUtils.getSession(); session.beginTransaction(); Class class1 = new Class(); class1.setName("07试点班"); Student student = new Student(); student.setClasser(class1); student.setStuName("###"); session.save(student); Student student2 = new Student(); student2.setClasser(class1); student2.setStuName("gg"); session.save(student2); session.getTransaction().commit(); }catch(Exception e) { e.printStackTrace(); session.getTransaction().rollback(); }finally { hibernateUtils.closeSession(session); } } }
发表评论
-
hibernate 集合映射
2009-10-14 14:43 746<hibernate-mapping> ... -
struts的ActionMessages消息机制(转java hain)
2009-10-04 22:35 1747本文 来自:http://hain.iteye.com/bl ... -
hibernate session 的缓存作用
2009-04-25 19:33 1786hibernatel 的三大作用: 每一个是: 减少仿 ... -
one to one 维一外键关联
2009-04-18 10:20 862hibernate一对一唯一外键关联映射(单向关联Person ... -
one to one 主键关联
2009-04-18 10:11 829<?xml version="1.0" ... -
one to many 双向关联
2009-04-18 10:08 783hihernate一对多关联映射(双向Classes<- ... -
one to many 单向
2009-04-18 10:00 1184hihernate一对多关联映射(单向Classes----- ... -
many to many 单向
2009-04-18 09:54 971hibernate多对多关联映射(单向User----> ... -
many to many 双向
2009-04-18 09:51 735<?xml version="1.0" ... -
hibernate 代理类错误lazyinitializationexception
2009-04-06 13:34 780lazyinitializationexception cou ... -
hibernate 一对一的主键映射 单向
2009-03-29 22:26 718其中最重要的还是***.hbm.xml 现在是一个人与一个 ... -
hibernate 一对多的映射
2009-03-29 20:26 943今天学了HIBERNATE的一对多的 关系,嗯它真的太好了,很 ... -
hibernate 实现分页
2009-03-28 16:43 668//Query 分页 public void testQue ... -
hibernate 的 save 或update 用一种ID对象
2009-03-28 15:46 854在save 前 如果new 的 User 与数据库里的id是一 ... -
hibernate get 和load 查询 区别
2009-03-28 15:13 1028hibernate 二种方法来select 的不同之处 get ... -
hibernate 生成一条数据 三种状态
2009-03-28 14:01 776hibernate 持久层有三种状态 transient ... -
hibernate dialect 方言错误
2009-03-28 12:57 1153一个错还找了我一天,啊,就是Hibernate 方言, &l ... -
hiber初步学习
2009-03-22 15:14 860以前学过Hiblernate 但现在忘的机乎是忘的干干净净了, ...
相关推荐
hibernate many to one 完整的程序,配套的jar 包,还有对应的数据库。 有清晰的注释!
NULL 博文链接:https://fqh1987.iteye.com/blog/791845
NULL 博文链接:https://xiangtui.iteye.com/blog/680938
第一阶段的工程 博文链接:https://selvemen.iteye.com/blog/458615
NULL 博文链接:https://liqita.iteye.com/blog/1497077
dc1.cc 实现many to one 的过程 dc2.cc 实现many to many的过程 dc3.cc 实现了对于数据中心瓶颈的改进 trace文件分为三个文件夹 trace1为dc1.cc的trace文件,即many to one 的trace文件; trace2为dc2.cc的trace文件...
关联映射的本质: 将关联关系映射到数据库,所谓的...<many-to-one>会在多的一端加入一个外键,指向一的一端,这个外键是由<many-to-one> 中的column属性定义的,如果忽略了这个属性那么默认的外键与实体的属性一致
many-to-one 配置详解 讲的很清楚 适合新手 值得下载
NULL 博文链接:https://zhouxianglh.iteye.com/blog/569471
深入理解hibernate many-to-one(多对一)及 cascade(级联).
7.5.1. one to many / many to one 7.5.2. one to one 7.5.3. many to many 7.6. More complex association mappings 8. Component Mapping 8.1. Dependent objects 8.2. Collections of dependent objects 8.3. ...
8.5.1. 一对多(one to many) /多对一( many to one) 8.5.2. 一对一(one to one) 8.5.3. 多对多(many to many) 9. 组件(Component)映射 9.1. 依赖对象(Dependent objects) 9.2. 在集合中出现的依赖...
Hibernate应用例子many-to-many
NULL 博文链接:https://zgdkik.iteye.com/blog/1835856
一对多(one to many) /多对一( many to one) 8.5.2. 一对一(one to one) 8.5.3. 多对多(many to many) 9. 组件(Component)映射 9.1. 依赖对象(Dependent objects) 9.2. 在集合中出现的依赖对象 ...
7.4.1. 一对多(one to many) / 多对一(many to one) 7.4.2. 一对一(one to one) 7.5. 使用连接表的双向关联(Bidirectional associations with join tables) 7.5.1. 一对多(one to many) /多对一( many to ...
7.5.1. 一对多(one to many) /多对一( many to one) 7.5.2. 一对一(one to one) 7.5.3. 多对多(many to many) 8. 组件(Component)映射 8.1. 依赖对象(Dependent objects) 8.2. 在集合中出现的依赖对象 ...
NHibernate One-to-Many一对多映射-xxlinux_com
7.4.1. 一对多(one to many) / 多对一(many to one) 7.4.2. 一对一(one to one) 7.5. 使用连接表的双向关联(Bidirectional associations with join tables) 7.5.1. 一对多(one to many) /多对一( many ...