-
关于MyEclipse建立的HibernateSessionFactory.java
2009-03-30
分类:
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://yourin.blogbus.com/logs/37246490.html
我们用MyEclipse开发基于HIBERNATE项目时候,Hibernate会自动简历一个HibernateSessionFactory类,但是当我们习惯了Configuration cfg=new Configuration().configure();的时候,再用HibernateSessionFactory就会出现莫名其妙的重定义错误:Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping org.young.hibernate.User
分析HibernateSessionFactory代码,发现在静态块已经给我们加载的configuration.configure("/hibernate.cfg.xml"),如果再加一遍当然是重复Mapping了!
解决方案
Session session=HibernateSessionFactory.getSessionFactory().buildSessionFactory().openSession();
或者直接HibernateSessionFactory.getSession();获取Session!
随机文章:
愛について 2009-09-06PHP函数__autoload()和spl_autoload_register() 2009-08-17随即读取数据库记录 2009-06-01再见,青岛 2009-04-18PHP的不可以 2009-04-18
收藏到:Del.icio.us








评论