1
這裏是一個錯誤:複製XML條目| Hibernate的orm.xml中
Exception in thread "main" javax.persistence.PersistenceException: Unable to build entity manager factory
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:66)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at ru.leon0399.podius.home.Core.run(Core.java:39)
at ru.leon0399.podius.home.Core.main(Core.java:34)
Caused by: java.lang.IllegalStateException: Duplicate XML entry for ru.leon0399.podius.common.entity.AbstractEntity
at org.hibernate.cfg.annotations.reflection.XMLContext.addClass(XMLContext.java:140)
at org.hibernate.cfg.annotations.reflection.XMLContext.addDocument(XMLContext.java:108)
at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.<init>(AnnotationMetadataSourceProcessorImpl.java:93)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.<init>(MetadataBuildingProcess.java:147)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:141)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:857)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:884)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)
... 4 more
這裏是我的orm.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings
xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
version="2.0">
<mapped-superclass class="ru.leon0399.podius.common.entity.AbstractEntity">
<attributes>
<id name="uuid">
<column name="uuid" column-definition="BINARY(16)"/>
</id>
<basic name="createdAt">
<column name="created_at" updatable="false"/>
<temporal>TIMESTAMP</temporal>
</basic>
<basic name="updatedAt">
<column name="updated_at"/>
<temporal>TIMESTAMP</temporal>
</basic>
</attributes>
</mapped-superclass>
這裏是我的AbstractEntity類
public abstract class AbstractEntity implements Creatable, Updatable, Entity {
private static final long serialVersionUID = 2544875895016856663L;
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractEntity.class);
private UUID uuid = UUID.randomUUID();
private Date updatedAt;
private Date createdAt;
// Getters and setters
}
正如你所看到的,沒有重複的東西
經過調試,我明白了,那個文件orm.xml
被讀爲TWICE! 下面是這個想法
所以你怎麼能我告訴Hibernate的不讀這種文件兩次確認截圖?
我猜'AbstractEntity'沒有註釋爲MappedSuperclass對嗎? – Apostolos
你能告訴我們AbstractEntity類嗎? – aksappy
@aksappy我已更新我的主題 – leon0399