SSH框架 Hibernate opensession()换成getcurrentsession()Junit测试不通过

只是简单的换了一下创建session的方法然后去掉了session,close()为什么JUNIT不通过了呢publicvoidtestTeacherSave(){Tea... 只是简单的换了一下创建session的方法 然后去掉了session,close()为什么JUNIT不通过了呢

public void testTeacherSave() {
Teacher t = new Teacher();
t.setName("t3");
t.setPassword("1234");

Session session = sf.getCurrentSession();
session.beginTransaction();
session.save(t);
session.getTransaction().commit();
}

输出结果
15:49:39,374 WARN org.hibernate.internal.util.xml.DTDEntityResolver:75 - HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
15:49:39,421 WARN org.hibernate.internal.util.xml.DTDEntityResolver:75 - HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
15:49:39,533 WARN org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl:93 - HHH000402: Using Hibernate built-in connection pool (not for production use!)
15:49:40,067 INFO org.hibernate.tool.hbm2ddl.SchemaUpdate:182 - HHH000228: Running hbm2ddl schema update
15:49:40,067 INFO org.hibernate.tool.hbm2ddl.SchemaUpdate:193 - HHH000102: Fetching database metadata
15:49:40,070 INFO org.hibernate.tool.hbm2ddl.SchemaUpdate:205 - HHH000396: Updating schema
15:49:40,084 INFO org.hibernate.tool.hbm2ddl.TableMetadata:66 - HHH000261: Table found: .student
15:49:40,084 INFO org.hibernate.tool.hbm2ddl.TableMetadata:67 - HHH000037: Columns: [id, name, password]
15:49:40,084 INFO org.hibernate.tool.hbm2ddl.TableMetadata:69 - HHH000108: Foreign keys: []
15:49:40,084 INFO org.hibernate.tool.hbm2ddl.TableMetadata:70 - HHH000126: Indexes: [primary]
15:49:40,093 INFO org.hibernate.tool.hbm2ddl.TableMetadata:66 - HHH000261: Table found: .teacher
15:49:40,093 INFO org.hibernate.tool.hbm2ddl.TableMetadata:67 - HHH000037: Columns: [id, name, password]
15:49:40,093 INFO org.hibernate.tool.hbm2ddl.TableMetadata:69 - HHH000108: Foreign keys: []
15:49:40,093 INFO org.hibernate.tool.hbm2ddl.TableMetadata:70 - HHH000126: Indexes: [primary]
15:49:40,094 INFO org.hibernate.tool.hbm2ddl.SchemaUpdate:242 - HHH000232: Schema update complete

JUNIT红条
用opensession绿条
展开
 我来答
zh2157524
2014-05-06 · TA获得超过462个赞
知道小有建树答主
回答量:387
采纳率:50%
帮助的人:404万
展开全部
没有在当前线程中找到 currentSession

使用静态变量创建currentSession 试试
更多追问追答
追问
刚刚试过了,把SessionFactory和Session都设成静态的 也不行
追答
你配置一下 currentsession的上下文试试

就是在hibernate.cfg.xml里面
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式