Java论坛网»Java技术»hibernate入门问题,急急急急急急
hibernate入门问题,急急急急急急
问?:
在structs框架下,运用hibernate连接oracle数据库 ,在以下地方报错,请高手指点啊,急急
Session session = sessionFactory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction(); // 就是这里,老报错,tx返回null
session.save(customer);
// We're done; make our changes permanent
tx.commit();
}catch (Exception e) {
if (tx != null) {
// Something went wrong; discard all partial changes
tx.rollback();
}
e.printStackTrace();
throw e;
} finally {
// No matter what, close the session
session.close();
}
Session session = sessionFactory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction(); // 就是这里,老报错,tx返回null
session.save(customer);
// We're done; make our changes permanent
tx.commit();
}catch (Exception e) {
if (tx != null) {
// Something went wrong; discard all partial changes
tx.rollback();
}
e.printStackTrace();
throw e;
} finally {
// No matter what, close the session
session.close();
}
答!: 1:
我来学习
高手帮忙顶
高手帮忙顶
答!: 2:
检查一下你的sessionFactory
答!: 3:
我用的hibernate.properties配置的
具体内容如下
hibernate.dialect= net.sf.hibernate.dialect.OracleDialect
hibernate.connection.driver_class= oracle.jdbc.driver.OracleDriver
hibernate.connection.username =scott
hibernate.connection.password =tiger
hibernate.connection.url =jdbc:oracle:thin:@localhost:1521:ORAC
具体内容如下
hibernate.dialect= net.sf.hibernate.dialect.OracleDialect
hibernate.connection.driver_class= oracle.jdbc.driver.OracleDriver
hibernate.connection.username =scott
hibernate.connection.password =tiger
hibernate.connection.url =jdbc:oracle:thin:@localhost:1521:ORAC
答!: 4:
问题解决,和大家初学者分享下吧 。
我用的structs框架,所有的类和映射文件都放在src下的org.db包下,我一开始把hibernate.properties也放在该包下,所以报错,后来我把hibernate.properties放到了src下就好了,我个人觉得初学者只看书的话一开始配置都会不知道把类文件,hibernate.properties,和映射文件放到哪。
我用的structs框架,所有的类和映射文件都放在src下的org.db包下,我一开始把hibernate.properties也放在该包下,所以报错,后来我把hibernate.properties放到了src下就好了,我个人觉得初学者只看书的话一开始配置都会不知道把类文件,hibernate.properties,和映射文件放到哪。
答!: 5:
是啊 我也出过这个问题 ,不过错一次以后就不会再错了。嘿嘿
答!: 6:
learn!!!
答!: 7:
学习中
相关JAVA教程:
c/s设想
程序提示:javax.naming.NameNotFoundException:env not found
关于spring默认单例模式的一点疑问
struts页面转换问题
请留住我对 Swing 的热情,请坚定我对 Swing 的信仰
考试系统的问题
怎么将Resultset里的内容在窗口表格中显示出来?
Netbeans编写JSP时放页面元素的问题
如何控制JTabbedPane的滚动按钮?
使用java代码创建树
struts上传文件出错!
关于工厂模式的问题