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绿条 展开
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绿条 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询