我正嘗試在Hibernate Tools Eclipse Add-On中使用Hibernate代碼生成功能。這是給我下面的錯誤:Eclipse中的問題Hibernate Tools
org.hibernate.InvalidMappingException:無法從資源解析映射文檔Alert.hbm.xml 無法解析映射文檔從資源Alert.hbm.xml org.hibernate.MappingException: class尋找屬性時沒有找到警報:alertId class尋找屬性時未找到警示:alertId org.hibernate.MappingException:class尋找屬性時未找到警示:alertId class尋找屬性時未找到警示: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.cfg.xml和Alert.hbm.xml)在哪裏?您試圖在代碼生成器中運行哪些出口商?你能成功創建一個Hibernate配置並查看映射/類嗎? – Shane