java - Eclipse Hibernate 工具的问题

标签 java eclipse hibernate hibernate-tools

我正在尝试使用 Hibernate Tools Eclipse Add-On 中的 Hibernate Code Generation 功能。它给了我以下错误:

org.hibernate.InvalidMappingException:无法从资源 Alert.hbm.xml 解析映射文档 无法从资源 Alert.hbm.xml 解析映射文档 org.hibernate.MappingException:查找属性时未找到警报类:alertId 查找属性时未找到警报类:alertId org.hibernate.MappingException:查找属性时未找到警报类:alertId 查找属性时未找到警报类:alertId java.lang.ClassNotFoundException:警报 警报

它没有找到类 Alert.java,但我认为代码生成器(因此得名...)应该为我生成所有 hibernate 类。

将 eclipse Indigo 与 Hibernate Tools 3.4.x 结合使用。

这是我的 hibernate.cfg.xml:

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
        <property name="connection.driver_class">
            com.mysql.jdbc.Driver
        </property>
        <property name="connection.url">
            jdbc:mysql://localhost:3306/findata?tcpKeepAlive=true
        </property>
        <property name="connection.username">root</property>
        <property name="connection.password">madmax1.</property>

        <property name="connection.pool_size">2</property>
        <property name="show_sql">true</property>
        <property name="dialect">
            org.hibernate.dialect.mysqldialect
        </property>
        <property name="current_session_context_class">thread</property>
        <property name="cache.provider_class">
            org.hibernate.cache.NoCacheProvider
        </property>

        <mapping resource="Alert.hbm.xml" />
        <mapping resource="Entity.hbm.xml" />
        <mapping resource="FactData.hbm.xml" />
        <mapping resource="TimeEvent.hbm.xml" />
        <mapping resource="User.hbm.xml" />
        <mapping resource="AlertTarget.hbm.xml" />
        <mapping resource="LogAlert.hbm.xml" />
    </session-factory>
</hibernate-configuration>

这是 Alert.hbm.xml:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="Alert" table="alerts">
        <id name="alertId" column="id">
            <generator class="assigned"/>
        </id>
        <property name="limitValue" column="limit_value" type="decimal" />
        <!-- The unique=true property makes the many-to-one a one-to-one relationship -->
        <many-to-one name="alertEntity" 
            class="Entity" column="entity_id" 
            not-null="true" cascade="all" unique="true"/>
        <set name="alert_targets" table="alerts_alert_targets" cascade="all">
            <key column="alert_id" />
            <many-to-many column="alert_target_id"
                class="AlertTarget" />   
        </set>
   </class>
</hibernate-mapping>

最佳答案

奇怪的是它正在寻找要生成的类。

我将检查 hibernate-reverse.xml 文件并检查它是否没有可能导致此问题的其他属性。

或者,在生成过程中,尝试设置 hibernate-revenge.xml 和 hibernate.cfg.xml,而不是使用现有的。

关于java - Eclipse Hibernate 工具的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10544232/

相关文章:

eclipse - 带插件的可移植 Eclipse Juno

java - Eclipse 看到库但无法导入它

java - 我可以重新导入已删除的 .git 文件而不丢失代码吗?

java - 让 Firebase 与 Java 一起工作,而不是 Android

java - struts2拦截器堆栈

java - 在线更新客户名单

java - java版本与我在环境变量中设置的版本不同

java - 存储对象时出现 ConstraintViolationException 1 :n relationship

java - Spring Webapp 与 Hibernate、注解驱动、一个又一个问题、源代码链接

java - 如何在具有不同行的多对一关系字典表中?