Hibernate简单的框架的基本配置??

long95wang 2011-07-06 10:38:03
各位兄弟姐妹,我在Hibernate框架配置文件的时候,不知道是数据哪里出现问题,导致无法运行,

下面是我写的代码以及配置文件


基本类文件:
package com.wish.model;

public class Userlogin {

private int id;
private String name;
private String password;

public Userlogin() {
super();
// TODO Auto-generated constructor stub
}
public Userlogin(int id, String name, String password) {
super();
this.id = id;
this.name = name;
this.password = password;
}

public Userlogin(String name, String password) {
super();
this.name = name;
this.password = password;
}

public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
*****************************************************
映射的 Userlogin.hbm.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle9iDialect</property>

<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>

<property name="current_session_context_class">thread</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="myeclipse.connection.profile">oracledriver</property>

<property name="connection.url">jdbc:oracle:thin:@127.0.0.1:1521:ORCL</property>

<property name="connection.username">scott</property>

<property name="connection.password">tiger</property>

<mapping resource="com/wish/model/Userlogin.hbm.xml"/>

</session-factory>
</hibernate-configuration>
*********************************************************
配置 hibernate.cfg.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.wish.model.Userlogin" table="userh">

<id name="id" column="Id" >
<generator class="sequence">
<param name="sequence">xulie</param>
</generator>
</id>

<property name="name" column="Username"></property>
<property name="password" column="Password"></property>

</class>
</hibernate-mapping>
*********************************************
测试*******java*******代码
package com.wish.model;

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

public class TextSave {

public static void main(String[] args){

Configuration cfg=new Configuration();
cfg.configure("hibernate.cfg.xml");
Transaction s=null;
SessionFactory sessionFactory=null;
Session session=null;
Userlogin user=null;
try{

sessionFactory=(SessionFactory) cfg.buildSessionFactory();

session=sessionFactory.openSession();

s.begin();

user=new Userlogin(4,"liuliu","liuliu");
session.save(user);

s.commit();
session.flush();
session.close();

}catch(HibernateException se){
System.out.println("+++"+se.getMessage());
}
}
}
*************************************抛出的异常代码******************************************************

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.AbstractMethodError: oracle.jdbc.driver.OracleDatabaseMetaData.getJDBCMajorVersion()I
at org.hibernate.engine.jdbc.JdbcSupportLoader.useContextualLobCreation(JdbcSupportLoader.java:78)
at org.hibernate.engine.jdbc.JdbcSupportLoader.loadJdbcSupport(JdbcSupportLoader.java:52)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:118)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2863)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1870)
at com.wish.model.TextSave.main(TextSave.java:21)













...全文
121 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
long95wang 2011-09-08
  • 打赏
  • 举报
回复
谢谢啦
zysnba 2011-07-08
  • 打赏
  • 举报
回复
驱动不兼容啊你在看看什么原因啊把你的错误查下啊
  • 打赏
  • 举报
回复
ojdbc14.jar
zn85600301 2011-07-07
  • 打赏
  • 举报
回复
在hibernate3.5.4,用oracle方言自动创建表出现如下错误:java.lang.AbstractMethodError: oracle.jdbc.driver.OracleDatabaseMetaData.getJDBCMajorVersion()I这是由于hibernate和oracle驱动的兼容问题造成的。oracle10g除了了提供了老的class12.jar驱动外,还提供了ojdbc14.jar驱动,其位于:C:\oracle\jdbc\lib。class12.jar会造成该错误,而ojdbcjar就好了。

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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