First info: I'm using:
Hibernate Annotations 3.4.0.GA
I need help about creating properly structure of db. Probably I don't good understand or I did mistake. I have some entities (File, Music, Playout, Playout_Files, Playout_Music) and I want that one object Playout have some File's and Music's for example:
Everything is OK, next I want add new entity Playout, example:
I've got error:
I understand that we cannot use the same item File and/or Music used in first Playout.
I tried use (the same for Music)
But it looks like wrong, I cannot explain it good..
How should I change structure/mapping that I can use again used item File?
I think you're telling us half of the truth. In your example you invoke the constructor: new Playout(2, 'Title2', files, musics)
Yet the class Playout only has the constructors: public Playout() & public Playout(String filetitle, Set<File> files, Set<Music> musics)
Maybe a typo.
Also why do you initialize musics but not versionFiles in Playout?
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Thank you for reply. You are right.. I said half of the truth.. I wrote it from member, Some code I was simplied for readers. I'll put whole methods:
I fixed code in Playout.java, initialization at begin code:
Eclipse recompiled whole code, next deploy on tomcat.
I started browser, clicked first time (I selected first Music, first File, entered name title of Playout and time)
and I see that it saved into db. Next I put new name title of Playout and time, selected again first Music, first File. And I've got error that:
When I selected second file from tableFile, second music from tableMusic it wrote successfully.
The problem in my opinion is in wrong structure that I cannot save the same Music/File used again as new entity Playout. Any ideas?
What is the constraint name that gets violated (see the exception)?
Joined: Aug 02, 2011
I see that constraint violated is PLAYOUT_MUSIC. And I understand that it has unique fields - it means that I cannot add music with ID used earlier.
To be preciselly: playout_music has 2 fields: playoutId, musicId. the both are unique. Example:
For me solution is: add next field unique like that: playoutmusicId.
How can I do it?
The same situation is for playout_files. I cannot add file with ID used earlier.
If I think wrong, please correct me.
Joined: Aug 02, 2011
OK, I'm read again book about Hibernate and I see that I did one mistake. It should be mapping @ManyToMany because entity File is used more than one in various entities Playout. The same is for entity Music.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com