Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6324061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:38:11+00:00 2026-05-24T16:38:11+00:00

I’ve just started with the Play Framework and I’m running into some problems using

  • 0

I’ve just started with the Play Framework and I’m running into some problems using a collection in one of my model classes. I am very new to Play and JPA/Hibernate, so please excuse my noobness… I’ve tried searching on the web for answers but couldn’t find what I was looking for.

Essentially, I have 2 models:

@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;
}

What I want here is to have all songs in the database and then a list to hold a subset of these songs temporarily (the list contents will change over time)… if the list is deleted, I don’t want the songs to be deleted (the songs shouldn’t hold any reference to the list). All I then try to do on application startup is load songs from a data file and insert a subset of songs into the list and save the list with the code below…. this is where I have had endless problems.

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();

If I leave out the flush call, the list doesn’t appear to be saved when fetching its contents from the DB later on. The flush call however results in the following exception:

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)

I realize I am probably doing something silly here (is the flush() after the persist really necessary?) and don’t understand how this stuff works properly, however, I’ve struggled to find information on this exact problem. Any help on how I should go about achieving the above will be greatly appreciated.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:38:12+00:00Added an answer on May 24, 2026 at 4:38 pm

    With the Play Framework, you don’t need to call persist. Try calling

    currentSongs.save();
    

    Also, the Play Framework will automatically create an id for your Song Model. Thus you may not need the songId unlessit is some predefined value you want to keep.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm making a simple page using Google Maps API 3. My first. One marker
I want use html5's new tag to play a wav file (currently only supported
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have some data like this: 1 2 3 4 5 9 2 6
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.