English 中文(简体)
游乐框架和在示范班中使用集
原标题:Play Framework and the use of collections in model classes

我刚刚从“游乐框架”开始,我会利用我的一门模式收集一些问题。 我对“游戏”和“JPA/Hibernate”非常新,因此,请原谅。 我在网上试图寻找答案,但找不到我所期待的东西。

基本上,我有两个模式:

@Entity
public class Song extends Model
{
    @Column(unique = true)
    public int songId;
    public String name;
    public String artist;

    public Song() {}

    public Song(int songId, String name, String artist)
    {
        this.songId = songId;
        this.name = name;
        this.artist = artist;
    }
}

@Entity
public class CurrentSongList extends Model {

    @OneToMany(orphanRemoval=false)
    public List<Song> currentSongList;
}

我在此想的是,数据库中的所有歌曲,然后是一份名单,以便暂时掌握这些歌曲的子集(清单内容会随着时间的推移而变化)。 在申请启动时,我试图做到的是从数据文档中打上歌曲,在清单中插入一小系列的歌曲,并将清单与以下编码相加。

Fixtures.deleteDatabase();
Fixtures.loadModels("songlist.yaml");

List<Song> songs = Song.findAll();
CurrentSongList.deleteAll();
CurrentSongList currentSongs = new CurrentSongList();
currentSongs.currentSongList = new ArrayList<Song>();
currentSongs.currentSongList.add(songs.get(0));
currentSongs.currentSongList.add(songs.get(1));

EntityManager em = JPA.em();
em.persist(currentSongs);
em.flush();

如果我离开了流动电话,名单在日后从非行提取内容时似乎就可节省。 然而,流体呼吁的结果如下:

Caused by: org.hibernate.HibernateException: Found two representations of same collection: models.CurrentSongList.currentSongList
    at org.hibernate.engine.Collections.processReachableCollection(Collections.java:175)
    at org.hibernate.event.def.FlushVisitor.processCollection(FlushVisitor.java:60)
    at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:122)
    at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:83)
    at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:77)
    at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:165)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:240)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
    at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:76)

我认识到,我或许会在这里做一些不sil的事情(即,在持续了真正必要的时间之后的流.?)并且不理解这种 st子是如何适当运作的,然而,我却竭力寻求有关这一具体问题的信息。 对我如何实现上述目标的任何帮助将受到高度赞赏。

Thanks!

最佳回答

根据《游乐框架》,你不需要打上<条码>。 电话

currentSongs.save();

此外,《游乐框架》还将自动为你的“先天模式”提供补助。 因此,你不需要<代码>。 Id,除非是你想要保持的某些预先界定的价值。

问题回答

暂无回答




相关问题
Multiple Hibernate instances using C3P0

I am facing a weird problem and it seems to be c3p0 related. I am starting two instances of an app in the same java vm which interact with each other. After some operations "APPARENT DEADLOCK" ...

Hibernate vs Ibatis caching

We can speed up a hibernate app easyly with 2nd level cache using infinispan or ehcache/terracotta,... but ibatis only have a simple interface to implement for caching. And hibernate knows more ...

Using annotations to implement a static join in hibernate

I m relatively new to hibernate and was wondering if someone could help me out. While I have no issues implementing a normal join on multiple columns in hibernate using the @JoinColumns tag, I m ...

Hibernate query with fetch question

I have a 2 entities in a One-To-Many relationship: OfficeView.java: public class OfficeView implements java.io.Serializable { private Integer officeId; private String addr1; private ...

hibernate interceptors : afterTransactionCompletion

I wrote a Hibernate interceptor : public class MyInterceptor extends EmptyInterceptor { private boolean isCanal=false; public boolean onSave(Object entity, Serializable arg1, Object[] arg2, String[]...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

Hibernate/GORM: collection was not processed by flush()

I have an integration test in my Grails application that fails when I try to save an entity of type Member invitingMember.save(flush: true) This raises the following exception org.hibernate....

Hibernate Criteria API equivalent for "elements()"

Is it possible to implement the following query using Criteria API? select order from ORDER as order,ITEM as item where item.itemID like ITM_01 and item in elements(order.items)

热门标签