xml文件从我的数据库映射一个新表但是当我启动项目时,我得到一个我无法理解和解决的重复属性映射错误。这是我的hibernate cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="session1">
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password"/>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/realestate</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="hibernate.connection.CharSet">utf8</property>
<property name="hibernate.connection.characterEncoding">utf8</property>
<property name="hibernate.connection.useUnicode">true</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.connection.CharSet">utf8</property>
<property name="hibernate.connection.characterEncoding">utf8</property>
<property name="hibernate.connection.useUnicode">true</property>
<mapping resource="entities/users.hbm.xml"/>
<mapping resource="entities/adminstration.hbm.xml"/>
<mapping resource="entities/seller.hbm.xml"/>
<mapping resource="entities/buyer.hbm.xml"/>
<mapping resource="entities/renter.hbm.xml"/>
<mapping resource="entities/leeser.hbm.xml"/>
<mapping resource="entities/house.hbm.xml"/>
<mapping resource="entities/userSellsHouse.hbm.xml"/>
<mapping resource="entities/userRentsHouse.hbm.xml"/>
<mapping resource="entities/messages.hbm.xml"/>
</session-factory>
</hibernate-configuration>
messages.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="entities.Message" table="MESSAGES" schema="realestate">
<id name="messageID" type="int">
<column name="messsageID" />
</id>
<property name="Date" type="java.lang.String">
<column name="Date" />
</property>
<property name="SenderID" type="java.lang.Integer">
<column name="Sender" />
</property>
<property name="ReceiverID" type="java.lang.Integer">
<column name="Receiver" />
</property>
<property name="Message" type="java.lang.String">
<column name="Message" />
</property>
<property name="Theme" type="java.lang.String">
<column name="Theme" />
</property>
</class>
</hibernate-mapping>
和Message persisent class:
public class Message {
int MessageID;
int SenderID;
int ReceiverID;
String date;
String message;
String theme;
public int getMessageID() {
return MessageID;
}
public void setMessageID(int messageID) {
MessageID = messageID;
}
public int getSenderID() {
return SenderID;
}
public void setSenderID(int senderID) {
SenderID = senderID;
}
public int getReceiverID() {
return ReceiverID;
}
public void setReceiverID(int receiverID) {
ReceiverID = receiverID;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getTheme() {
return theme;
}
public void setTheme(String theme) {
this.theme = theme;
}
}
这是错误
...
Caused by: org.hibernate.MappingException: Duplicate property mapping of SenderID found in entities.Messages
at org.hibernate.mapping.PersistentClass.checkPropertyDuplication(PersistentClass.java:515)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:505)
at org.hibernate.mapping.RootClass.validate(RootClass.java:270)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1358)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1849)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
at database.HibernateUtil.<clinit>(HibernateUtil.java:15)
... 46 more
修改:我尝试在cfg文件中注释掉<mapping resource="entities/messages.hbm.xml"/>
,但仍然遇到同样的错误。
Edit2:以上是来自java EE项目,我复制了在simle java项目中粘贴所有东西,它运行正常。有什么建议吗?
编辑3:我在邮件类中添加了最终修饰符,以确保它不能被继承
答案 0 :(得分:2)
请浏览以下链接,这可能对您有所帮助......
<强> Hibernate ORMHHH-2598 强>
如果集合键不为null,则使用相同的集合名称映射来自两个不同类的实体集合会导致重复的backref属性异常