【联合主键】
>>>>配置方式:xml:
1. Student中单独创建StudentPk主键实体类
2. 配置:
<composite-id name="studentPK"> <key-property name="name" column="username" /> <key-property name="nickname" column="nickname" /> </composite-id>
>>>>注解方式:annotation
1. Teacher中单独创建TeacherPk主键实体类
2.注解
** 注解方式1:【一个注解】※常用
<1>
@EmbeddedId public TeacherPk getTeacherPk()
<2>主键类实现Serializable接口+重写hashCode和equals方法。
TeacherPk implements Serializable{ @Override public int hashCode() @Override public boolean equals(Object obj) }
**注解方式2:【两个注解】
<1>
@Embeddable public class TeacherPk implements Serializable
@Id public TeacherPk getTeacherPk()
<2>同上
【openSession和getCurrentSession区别】
1. openSession产生的实例是SessionImpl.class的实例;
getCurrentSession产生的是$Proxy代理类实例
2. openSession每次调用产生新的Session;
getCurrentSession在第一次调用时生成新的Session,之后关联到上下文,
在事务完成(commit/rollback)之前,每次得到的都是已经存在的Session,
直到事务提交或者回滚。
3. openSession的Session需要手动close();
getCurrentSession的会在事务完成(commit/rollback)时自动close。
4. openSession的可以直接使用。
getCurrentSession需要再hibernate的配置文件中配置current_session_context_class.。比如:
<property name="current_session_context_class">thread</property>
相关推荐
关键问题有几个,第一个HibernateDaoSupport这个没有了,在使用hibernateTemplate的时候,报错误:java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session 很是悲...
博文链接:https://shaqiang32.iteye.com/blog/201918
NULL 博文链接:https://bbxyhaihua.iteye.com/blog/505085
---------------Hibernate3.0 配置-------------- 1.Hibernate中配置参数 /** * 注意:HQL中使用参数的方法: * 1.根据参数名称来设置参数:匹配名称; * 2.根据参数位置来设置参数:匹配位置; */ //根据参数名称来...
对 Hibernate 初体验 1.新建一个java工程,工程名为Hiberante1 2.导入相应的jar包 1)hibernate需要导入这些包 2)因为我们需要操作数据库所以要导入数据库的包,我用的mysql数据库 3.创建数据库以及表 ...
hibernate 学习笔记: 了解hibernate的基本概念 配置hbm.xml cfg.xml 快速入门案例3: 从domain-xml-数据库表 ...openSession()和getCurrentSession() 线程局部变量模式 transaction事务 在web项目中开发hibernate
一,集成 Spring 与 Hibernate 1,配置SessionFactory 1,配置 ---------------------- applicationContext.xml ------------------------ <!-- 配置SessionFactory(整合Hibernate) --> ...
//该方法将到classpath下解析hibernate.cfg.xml中的配置,如果不用Hibernate默认的配置文件名和路径,可在该方法中指定Hibernate配置文件的名称和路径 2.用Configuration对象获取SessionFactory和Session对象:...
Spring4.0+Hibernate4.0+Struts2.3整合案例:实现增删改查。 ===================== application.xml: <?xml version="1.0" encoding="UTF-8"?> xmlns="http://www.springframework.org/schema/beans" xmlns:xsi=...
hibernate 分页查询的实现 hibernate 内置的有分页功能 有三个参数 thisnumber一个是当前页数 sumcount是一页显示多少条数据 sql是用来查询的sql语句 public List getPageList(int thisNumber, int sumCount, ...
9、openSession和getCurrentSession 90 10、拦截器的作用?拦截器和过滤器的区别? 91 11、struts.xml中result的type有哪些类型? 91 12、什么时候用JDBC什么时候用Hibernete; 91 13、hibernate 数据的三个状态 91 ...
1)配置环境,加载hibernate的jar文件,以及连接数据库连接使用的jar文件,并配置CLASSPATH环境变量。 2)写POJO类(普通的java类) 3)写hibernate所需的配置文件,hibernate.cfg.xml ,Xxxxx.hbm.xml 4)调用...
sessionFactory.openSession() : null; threadLocal.set(session); } return session; } /** * Rebuild hibernate session factory * */ public static void rebuildSessionFactory() { try { ...
hibernate 经典文档,学习hibernate 必备的文档,深入浅出,非常实用,强烈推荐!
123.在 hibernate 中 getCurrentSession 和 openSession 的区别是什么? 124.hibernate 实体类必须要有无参构造函数吗?为什么? 十三、Mybatis 125.mybatis 中 #{}和 ${}的区别是什么? 126.mybatis 有几种分页方式...
修改Hibernate3.2.6ga可以动态通过Session设置Schema Session session=sf.openSession(); session.setSchema("SchemaName"); session.save........ ....... .......
{****************************************************************************** * * * PROJECT : EOS Digital Software Development Kit EDSDK * * NAME : EDSDKApi.pas * * * * Description: This is the ...
例如以下代码先加载一个持久化对象,然后通过delete()方法将它删除: Session session1 = sessionFactory.openSession(); Transaction tx1 = session1.beginTransaction(); // 先加载一个持久化对象 Customer ...