我正在将Hibernate
版4.3.11
与H2 database
版1.3.172
一起使用
因此,客户获得了此异常(从未有过)
Found two representations of same collection: com.jthink.songlayer.Song.coverArts
org.hibernate.HibernateException: Found two representations of same collection: com.jthink.songlayer.Song.coverArts
at org.hibernate.engine.internal.Collections.processReachableCollection(Collections.java:170)
at org.hibernate.event.internal.FlushVisitor.processCollection(FlushVisitor.java:59)
at org.hibernate.event.internal.AbstractVisitor.processValue(AbstractVisitor.java:121)
at org.hibernate.event.internal.AbstractVisitor.processValue(AbstractVisitor.java:82)
at org.hibernate.event.internal.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:76)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:172)
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:231)
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:102)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:55)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1258)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:425)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:177)
at com.jthink.songkong.ituneshelper.WindowsUpdateItunesWithChanges.analyseFiles(WindowsUpdateItunesWithChanges.java:296)
at com.jthink.songkong.ituneshelper.WindowsUpdateItunesWithChanges.updateItunes(WindowsUpdateItunesWithChanges.java:175)
at com.jthink.songkong.ituneshelper.UpdateItunesWithChanges.call(UpdateItunesWithChanges.java:185)
at com.jthink.songkong.ituneshelper.UpdateItunesWithChanges.call(UpdateItunesWithChanges.java:33)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown S
我知道这可能会因多种原因而发生,但是奇怪的是,当我提交事务时发生了这种情况,在特定的休眠会话期间,我仅加载一个类,而实际上从未对该类进行任何更改>
我的Song
类具有指向“ coverArts”的链接
@OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL})
private List<CoverArt> coverArts;
CoverArt类是
package com.jthink.songlayer;
import org.hibernate.envers.Audited;
import javax.persistence.*;
/**
* Links between a song and the artwork for that song.
*/
@Audited
@Entity
public class CoverArt
{
private String imageType;
private String description;
@OneToOne
private CoverImage coverImage;
public CoverArt()
{
}
@Id
@GeneratedValue
private Integer id;
@Version
private int version;
public String getImageType()
{
return imageType;
}
public void setImageType(String imageType)
{
this.imageType = imageType;
}
public String getDescription()
{
return description;
}
public void setDescription(String description)
{
this.description = description;
}
public CoverImage getCoverImage()
{
return coverImage;
}
public void setCoverImage(CoverImage coverImage)
{
this.coverImage = coverImage;
}
}