我正在尝试使用 Hibernate Tools Eclipse Add-On 中的 Hibernate Code Generation 功能。它给了我以下错误:
org.hibernate.InvalidMappingException:无法从资源 Alert.hbm.xml 解析映射文档 无法从资源 Alert.hbm.xml 解析映射文档寻找属性时:alertId org.hibernate.MappingException:找不到类警报 寻找属性时:alertId 类警报未找到 寻找属性时:alertId java.lang.ClassNotFoundException:警报警报
它没有找到类 Alert.java 但我认为代码生成器(因此得名......)应该为我生成所有休眠类。
将 eclipse Indigo 与 Hibernate Tools 3.4.x 一起使用。
这是我的 hibernate.cfg.xml:
<!DOCTYPE hibernate-configuration PUBLIC
"-//休眠/休眠配置 DTD 3.0//EN"
“http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd”>
<休眠配置>
<会话工厂>
<!-- 数据库连接设置 -->
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</属性>
<property name="connection.url">
jdbc:mysql://localhost:3306/findata?tcpKeepAlive=true
</属性>
<property name="connection.username">根</property>
<property name="connection.password">madmax1.</property>
<property name="connection.pool_size">2</property>
<property name="show_sql">真</property>
<属性名称="方言">
org.hibernate.dialect.mysql方言
</属性>
<property name="current_session_context_class">线程</property>
<property name="cache.provider_class">
org.hibernate.cache.NoCacheProvider
</属性>
<映射资源="Alert.hbm.xml" />
<映射资源="Entity.hbm.xml" />
<映射资源="FactData.hbm.xml" />
<映射资源="TimeEvent.hbm.xml" />
<映射资源="User.hbm.xml" />
<映射资源="AlertTarget.hbm.xml" />
<mapping resource="LogAlert.hbm.xml" />
</会话工厂>
</hibernate-configuration>
这是 Alert.hbm.xml:
<?xml 版本="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate 映射 DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<休眠映射>
<类名=“警报”表=“警报”>
<id name="alertId" column="id">
<generator class="assigned"/>
</id>
<property name="limitValue" column="limit_value" type="decimal" />
<!-- unique=true 属性使多对一成为一对一关系 -->
<多对一名称="alertEntity"
类=“实体”列=“实体ID”
not-null="true" 级联="all" unique="true"/>
<set name="alert_targets" table="alerts_alert_targets" cascade="all">
<key column="alert_id" />
<多对多列="alert_target_id"
类="警报目标" />
</set>
</class>
</hibernate-mapping>