楼上的大哥你干脆告诉我怎么做能解决这个问题吧 我刚刚开始学习hibernate 不是很清楚你说的 谢谢
解决方案 »
- javamail 收邮件时候内容重复 怎么过滤重复内容.... 100分给了.
- 请问用Eclipse开发servlet和用MyEclipse开发操作上有什么不同的地方?
- 求一正则表达式
- iReport 3.13 出错啦。。。
- 用TOMCAT发布的时候在webapps底下放一个.jsp文件,浏览器里面输http://localhost;8080/*.jsp就抱错
- struts2错误信息的输出问题
- 大家好,请教关于JBOSS 部署发布的问题
- tomcat和resin的中文问题
- 求救:请教struts能否与Wap的WML结合使用!急
- 求搜索引擎原理。
- struts+spring+hibernate框架入门文章
- java.lang.OutOfMemoryError: PermGen space tomcat6.16+apache2.26+php2.5
<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> hibernate.cfg.xml不能在src下面放着!
要放到classpath的路径下面,就是编译好的类路径下面,才能读取到!!!
hibernate.cfg.xml一般是放在src的根目录下,编译后在在输入的根目录下应该也要有,不然加载不到
config.addClass(XXX.class);//自己指定.class文件
其他ide有些需要设置。
楼主检查下 放class的地方是否有文件,同时检查配置,你用myeclipse自动生成的吧。
你的sessionfactory如何加载的?
<!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());
}}看看创建链接是否成功
2:从org.hibernate.HibernateException: Hibernate Dialect must be explicitly set 可以推断,根本咩有读取到你的配置信息
3:把你的测试类贴出来
,然后把配置文件放到class下居然好了。谢谢。