(在线痴等)hibernate+oracle出现了错误。求解

classlj 2010-08-11 12:05:43
<property name="hibernate.connection.url">
jdbc:oracle:thin:@localhost:1521:LUJIE
</property>
<property name="hibernate.connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">HELLO</property>
<property name="hibernate.dialect">
org.hibernate.dialect.OracleDialect
</property>
<property name="hibernate.show_sql">true</property>


我在配置文件里这样配的 错误提示是 必须给用户已个JDBC的连接
...全文
159 19 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
classlj 2010-08-11
  • 打赏
  • 举报
回复
提示出 错误的代码在关闭Session 那一块
classlj 2010-08-11
  • 打赏
  • 举报
回复
包绝对加进去了
duyu1025 2010-08-11
  • 打赏
  • 举报
回复
你那样配也没有错吧。。这是我自己配的写的是hibernate.properties
hibernate.connection.username=XXXX
hibernate.connection.url=jdbc:oracle:thin:@172.18.4.18:1521:als
hibernate.connection.password=XXXXXXX
hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
hibernate.dialect=org.hibernate.dialect.Oracle9Dialect
hibernate.myeclipse.connection.profile=myoracle
hibernate.jdbc.batch_size=50
duyu1025 2010-08-11
  • 打赏
  • 举报
回复
看你的错误消息也看不出是你配错了啊,确认包都加了没有? java.lang.NoClassDefFoundError
classlj 2010-08-11
  • 打赏
  • 举报
回复
java.lang.NoClassDefFoundError
at hibernate.TestFile.testaa(TestFile.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

饭炒蛋2009 2010-08-11
  • 打赏
  • 举报
回复
呵呵 。。。。
xiaozhao32 2010-08-11
  • 打赏
  • 举报
回复
不对的话 贴下错误代码
xiaozhao32 2010-08-11
  • 打赏
  • 举报
回复
property name中去掉hibernate.
classlj 2010-08-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 xiaozhao32 的回复:]
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
[/Quote]

不对
xiaozhao32 2010-08-11
  • 打赏
  • 举报
回复
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
kc8886 2010-08-11
  • 打赏
  • 举报
回复
可能是你的jar包有问题 换个试试
java.lang.NoClassDefFoundError
分明是找不到类
classlj 2010-08-11
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 humijnjie227 的回复:]
你有加ORCL的class12.jar
[/Quote]

有加
humijnjie227 2010-08-11
  • 打赏
  • 举报
回复
你有加ORCL的class12.jar
duyu1025 2010-08-11
  • 打赏
  • 举报
回复
你直接关session,干嘛还封闭一层呢,你换成session.close()看看,自己我试试,这种bug自己调了。
duyu1025 2010-08-11
  • 打赏
  • 举报
回复
session.beginTransaction().commit();

换成 session.getTransaction().commit();
xiaozhao32 2010-08-11
  • 打赏
  • 举报
回复
看看这行 是什么报空指针吧
java.lang.NoClassDefFoundError
at hibernate.TestFile.testaa(TestFile.java:70)
classlj 2010-08-11
  • 打赏
  • 举报
回复
封装好的类

package moxing;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateList {

private static SessionFactory factory;

static {
try {
Configuration cfg = new Configuration().configure();
factory = cfg.buildSessionFactory();
}catch(Exception e) {
e.printStackTrace();
}
}

public static SessionFactory getSessionFactory() {
return factory;
}

public static Session getSession() {
return factory.openSession();
}

public static void closeSession(Session session) {
if (session != null) {
if (session.isOpen()) {
session.close();
}
}
}
}




下面是单元测试

public void testaa(){

Session session=null;
try{
session=HibernateList.getSession();
session.beginTransaction();

User user=new User();
user.setName("A");
user.setSj(new Date());
session.save(user);


session.beginTransaction().commit();

}catch(Exception e){
e.printStackTrace();
session.getTransaction().rollback();
}finally{
HibernateList.closeSession(session);
}

}
duyu1025 2010-08-11
  • 打赏
  • 举报
回复
那把你用session那块贴出来噻,还有错误。。。
用<property /> 这种写法 name 前面 不要写hibernate,用properties文件要加上hibernate
LovePythonic 2010-08-11
  • 打赏
  • 举报
回复
你先看看你是用什么方式连接数据库的,dbcp?C3P0?不同的包,配置的属性是不同。检查属性名。。。

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧