Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with creating db - what's wrong?

 
Paul Silesian
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,


I'm new here .

First info: I'm using:
Hibernate Annotations 3.4.0.GA
Hibernate 3.3.0.SP1

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?

Is it possible do it?



Below full code and some data examples:




Below file Playout.java



Below file File.java



Below file Music.java




Best regards,
Paul
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the JavaRanch!
 
Paul Silesian
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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?


Best regards,
Paul Silesian

 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the constraint name that gets violated (see the exception)?
 
Paul Silesian
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

playoutId, musicId
1,1
1,2
1,3

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.


Best regards,
Paul Silesian
 
Paul Silesian
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Below solution:

in Playout.java




Best regards,
Paul Silesian
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic