【问题标题】:Hibernate code generation: org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available休眠代码生成:org.hibernate.HibernateException:没有可用连接时必须设置“hibernate.dialect”
【发布时间】:2023-03-19 19:43:02
【问题描述】:

我在 Eclipse Mars 中尝试使用 Hibernate Tool Code generation 时遇到了这个问题。我的hibernate.cfg.xml 中已经有方言,包括sqljdbc4.jar

org.hibernate.HibernateException: 'hibernate.dialect' 没有可用连接时必须在此处设置输入代码


hibernate.cfg.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 name="">
  <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
  <property name="hibernate.connection.password">123</property>
  <property name="hibernate.connection.url">jdbc:sqlserver://localhost:1433;databaseName=Qlsach</property>
  <property name="hibernate.connection.username">sa</property>
  <property name="hibernate.show_sql">true</property>
  <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
 </session-factory>
</hibernate-configuration>


hibernate.reveng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >

<hibernate-reverse-engineering>
  <table-filter match-catalog="QLSACH" match-schema="dbo" match-name="DanhMuc"/>
  <table-filter match-catalog="QLSACH" match-schema="dbo" match-name="sach"/>
</hibernate-reverse-engineering>

【问题讨论】:

  • 你是如何尝试创建会话工厂的?您可以在此处添加该代码吗?
  • 我还没有创建会话工厂。我只是创建项目,创建 cfg.xml、reveng.xml 并尝试生成 POJO 类和映射 xml 文件。我在 NetBeans 中完美地完成了这项工作,但在 Eclipse 中却没有。
  • 在 eclipse mars 中你在哪里指定 reveng.xml ?我找不到在哪里可以添加它

标签: eclipse hibernate code-generation dialect


【解决方案1】:

我通过在 Hibernate 配置对话框的“Main”选项卡中将 Hibernate 版本从 5.1 更改为 4.3 解决了这个问题。

【讨论】:

  • 通过在项目/休眠设置中指定“类型:核心”解决了类似的问题。
猜你喜欢
  • 2015-01-04
  • 2012-05-09
  • 2014-09-18
  • 1970-01-01
  • 2017-02-28
  • 1970-01-01
  • 2012-07-14
  • 2015-03-21
  • 1970-01-01
相关资源
最近更新 更多