还是hibernate问题(高手进)

apache0000 2009-12-21 04:16:52
这样的代码:
package myFamily;


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

public class Explorer {

public static void main(String[] args) {

Configuration conf=new Configuration().configure();
SessionFactory sf=conf.buildSessionFactory();
Session se=null;
User u=new User();
u.setName("xuxiao");
try{
se=sf.openSession();
se.beginTransaction();
se.getTransaction().begin();
se.save(u);
se.getTransaction().commit();
}catch(Exception e){
e.printStackTrace();
}finally{
se.close();
}

}
}




报这样的错:
Exception in thread "main" java.lang.AbstractMethodError: oracle.jdbc.driver.OracleDatabaseMetaData.supportsGetGeneratedKeys()Z
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:123)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2119)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339)
at myFamily.Explorer.main(Explorer.java:14)


...全文
335 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
丑陋的小可怜 2010-01-06
  • 打赏
  • 举报
回复
se.getTransaction().begin();
这是什么意思 不是前面一句就打开了吗? 这里又开一次做什么
一个 session.beginTransaction() 就已经开启事务了!

还有 这怎么就是驱动包的问题了?

还有楼上那个要修改url的 这个有什么关系?
howsun 2009-12-21
  • 打赏
  • 举报
回复
楼主用了Oracle的关键字吧?
上树的蜗牛儿 2009-12-21
  • 打赏
  • 举报
回复
楼主url写错了,不能这样写:
<property name="hibernate.connection.url">
jdbc:oracle:thin:@192.168.5.160:1521:my0id
</property>

改成:
<property name="hibernate.connection.url">
jdbc:oracle:thin:@127.0.0.1:1521:my0id
</property>

<property name="hibernate.connection.url">
jdbc:oracle:thin:@localhost:my0id
</property>


kky2010_110 2009-12-21
  • 打赏
  • 举报
回复
jdbc:oracle:thin:@192.168.5.160:1521::oracle9i
道光2008 2009-12-21
  • 打赏
  • 举报
回复
楼主明显写错啦:
参考:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
  PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory>

 <property name="connection.url">jdbc:hsqldb:hsql://localhost</property>
 <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
 <property name="connection.username">sa</property>
 <property name="connection.password"></property>
 <property name="dialect">net.sf.hibernate.dialect.HSQLDialect</property>

 <property name="hibernate.show_sql">false</property>

 <mapping resource="Cat.hbm.xml"/>

</session-factory>
</hibernate-configuration>
apache0000 2009-12-21
  • 打赏
  • 举报
回复
我这个hibernate,建表没问题,
一插入记录就报这样的错。

以下配置都试过了,报同样的错
org.hibernate.dialect.Oracle8iDialect
org.hibernate.dialect.Oracle9iDialect
org.hibernate.dialect.Oracle10gDialect
zl3450341 2009-12-21
  • 打赏
  • 举报
回复
public class AbstractMethodError
extends IncompatibleClassChangeError
当应用程序试图调用一个抽象方法时,抛出此错误。
通常由编译器捕获此错误;如果某个类的定义自当前执行方法最后一次编译以后作了不兼容的更改,
则此错误只可能在运行时发生。


数据库驱动换个看看
数据库和hibernate.dialect是一致的吗?
wzju64676266 2009-12-21
  • 打赏
  • 举报
回复
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>
<class name="myFamily.User" table="person">
<id name="num">
<generator class="uuid"></generator>
</id>
<property name="name" />
</class>
</hibernate-mapping>


你这个type column都没写,不知道有没有关系
wzju64676266 2009-12-21
  • 打赏
  • 举报
回复
应该是驱动包的问题
apache0000 2009-12-21
  • 打赏
  • 举报
回复
顶一下,盼回复
apache0000 2009-12-21
  • 打赏
  • 举报
回复
hibernate.cfg.xml
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.url">
jdbc:oracle:thin:@192.168.5.160:1521:my0id
</property>
<property name="hibernate.connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>
<property name="hibernate.connection.username">xuxiao</property>
<property name="hibernate.connection.password">0000</property>
<property name="hibernate.dialect">
org.hibernate.dialect.Oracle9iDialect
</property>
<mapping resource="myFamily/User.hbm.xml" />
</session-factory>
</hibernate-configuration>



User.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>
<class name="myFamily.User" table="person">
<id name="num">
<generator class="uuid"></generator>
</id>
<property name="name" />
</class>
</hibernate-mapping>

帮忙看看什么原因
道光2008 2009-12-21
  • 打赏
  • 举报
回复
hibernate的配置文件存在问题
panhaichun 2009-12-21
  • 打赏
  • 举报
回复
配置文件都没弄进来
APOLLO_TS 2009-12-21
  • 打赏
  • 举报
回复
这个跟数据库版本,驱动,方言有很大关系。你发的代码意义不是很大。

67,515

社区成员

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

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