首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

hibernate dialect 有关问题

2012-03-19 
hibernate dialect 问题2008-10-11 1:04:24 org.hibernate.connection.UserSuppliedConnectionProvider co

hibernate dialect 问题
2008-10-11 1:04:24 org.hibernate.connection.UserSuppliedConnectionProvider configure
警告: No connection properties specified - the user must supply JDBC connections
org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:437)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:132)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2078)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1302)
at com.hibernate.utils.HibernateTest.TestSave(HibernateTest.java:20)
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:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
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:120)
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)
请各位大虾 给小弟看看 这是什么原因 数据库方言在hibernate配置文件中已经正确配置了 但是还是出现这个问题 
<session-factory>
<property name="connection.username">root</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/test
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="myeclipse.connection.profile">
mysql
</property>
<property name="connection.password">
gf851012
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="show_sql">true</property>
<mapping resource="com/hibernate/dao/Events.hbm.xml" />

</session-factory>
我在线等待各位的答案 谢谢 十分感谢!!!


[解决办法]
hibernate.cfg.xml 放哪了
[解决办法]

[解决办法]
换为以下内容试一下:
<session-factory> 
<property name="connection.username">root </property> 
<property name="connection.url"> 
jdbc:mysql://localhost:3306/test 
</property> 
<property name="dialect"> 
org.hibernate.dialect.MySQLInnoDBDialect
</property> 
<property name="myeclipse.connection.profile"> 
mysql 
</property> 
<property name="connection.password"> 
gf851012 
</property> 
<property name="hibernate.connection.driver_class"> 


com.mysql.jdbc.Driver 
</property> 
<property name="show_sql">true </property> 
<mapping resource="com/hibernate/dao/Events.hbm.xml" /> 
</session-factory> 

[解决办法]
<property name="connection.user">
用户名没有配置!
</property> 

hibernate.cfg.xml不能在src下面放着!
要放到classpath的路径下面,就是编译好的类路径下面,才能读取到!!!

[解决办法]
驱动是否加入到classpath中
hibernate.cfg.xml一般是放在src的根目录下,编译后在在输入的根目录下应该也要有,不然加载不到
config.addClass(XXX.class);//自己指定.class文件




[解决办法]

探讨
<property name="connection.user">
用户名没有配置!
</property>

hibernate.cfg.xml不能在src下面放着!
要放到classpath的路径下面,就是编译好的类路径下面,才能读取到!!!

[解决办法]
<?xml version="1.0" encoding="UTF-8"?>
<!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="connection.username">root</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/test
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="myeclipse.connection.profile">mysql</property>
<property name="connection.password">king</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>

<!-- <property name="hibernate.connection.datasource">java:/comp/env/jdbc/store</property> -->
<!-- <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.username">store</property>
<property name="connection.password">store</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property> -->
<property name="show_sql">true</property>
<!-- <mapping resource="cn/hibernate/trade_sort.hbm.xml" />
<mapping resource="cn/hibernate/merchandise.hbm.xml" />
<mapping resource="cn/hibernate/stocklist.hbm.xml" />
<mapping resource="cn/hibernate/measureUnit.hbm.xml" /> -->
</session-factory>
</hibernate-configuration>


在用这个测试一下
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class Hibernate_session {

private static SessionFactory hibernateSessionFactory;

private static Session hibernateSession;

private static ThreadLocal<Session> localSession = new ThreadLocal<Session>();

static{
hibernateSessionFactory = new Configuration().configure("/hibernate.xml").buildSessionFactory();
}

public static Session getHibenateSession(){
if(localSession.get()==null){
hibernateSession = hibernateSessionFactory.openSession();
localSession.set(hibernateSession);


return hibernateSession;
}
else{
return localSession.get();
}
}
public static void closeSession(){
if(localSession.get()!=null){
localSession.set(null);
}
}
public static void main(String []str){

Session sission = getHibenateSession();
System.out.println(sission.connection());
}

}

看看创建链接是否成功
[解决办法]
1:驱动JAR有没有在环境变量里
2:从org.hibernate.HibernateException: Hibernate Dialect must be explicitly set 可以推断,根本咩有读取到你的配置信息
3:把你的测试类贴出来

热点排行