使用hibernate出错了!

ITdavid 2006-03-09 11:58:56
我在使用myeclipse的hibernate功能时,在一个测试Test.java文件中写到:

Session session = (Session) HibernateSessionFactory.currentSession();//报错
Transaction transaction = session.beginTransaction();
transaction.commit();
HibernateSessionFactory.closeSession();

而HibernateSessionFactory类中的:

private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
private static final Configuration cfg = new Configuration();
...
cfg.configure(CONFIG_FILE_LOCATION);
sessionFactory = cfg.buildSessionFactory();//报错

他们的错误是:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.HibernateException: database product name cannot be null
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:374)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:110)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1463)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1004)
at hb.Test.main(Test.java:25)

上面两处出错,是什么原因,是不是hibernate.cfg.xml的问题?
...全文
64 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ITdavid 2006-03-10
  • 打赏
  • 举报
回复
up
CristinNa 2006-03-10
  • 打赏
  • 举报
回复
上面的log4j不是错误,而是警告,是因为log4j没有配置,这是无关紧要的,与Hibernate无关
是hibernate.cfg.xml的问题

81,094

社区成员

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

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