-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem with creating db - what's wrong?
PostPosted: Tue Aug 02, 2011 3:28 am 
Newbie

Joined: Sun Jul 31, 2011 9:15 am
Posts: 1
Hi all,

I'm using:
Hibernate Annotations 3.4.0.GA
Hibernate 3.3.0.SP1
DB: HSQLDB 2.1.0
Java: 1.6.0_26
OS: Windows XP

I need help about creating properly structure of db. 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:

Code:
Set<File> files = new HashSet<File>();
files.add( // selected first file from entity File )

Set<Music> musics = new HashSet<Music>();
musics.add( // selected first music from entity Music )

new Playout(1,'Title1', files, musics);


Everything is OK, next I want add new entity Playout, example:

Code:
Set<File> files = new HashSet<File>();
files.add( // selected first file from entity File )

Set<Music> musics = new HashSet<Music>();
musics.add( // selected first music from entity Music )

new Playout(2, 'Title2', files, musics)


I've got error:
Code:
36750 ["http-bio-8080"-exec-9] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: -104, SQLState: 23505
36750 ["http-bio-8080"-exec-9] ERROR org.hibernate.util.JDBCExceptionReporter - integrity constraint violation: unique constraint or index violation; SYS_CT_10052 table: PLAYOUT_MUSIC
36750 ["http-bio-8080"-exec-9] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update



How should I change structure/mapping that I can use again used item File?


Below some data from db and code entities:

Code:
SELECT * FROM File;
FILEID   FILENAME
1   file1
2   file2
3   file3
4   file4
5   file5


Code:
SELECT * FROM Music;
MUSICID   COMPOSER   MUSICTITLE   TIME
1   ComposerA   Title1      00:20:00
2   ComposerB   Title2      00:21:00
3   ComposerC   Title3      00:21:00
4   ComposerD   Title4      00:23:00
5   ComposerE   Title5      00:25:00


Code:
SELECT * FROM Playout;
PLAYOUTID   TIME      TITLE
1      2011-07-31   Title1


Below file Playout.java

Code:
@Entity
@Table(name="PLAYOUT")
public class Playout implements Serializable {

   @Id
   @GeneratedValue
   @Column(name = "playoutId")
   private Long playoutId;
   private String title;
   private Set<File> versionFiles;
   private Set<Music> musics = new HashSet<Music>(0);

   public Playout() {}
   
   public Playout(String filetitle, Set<File> files, Set<Music> musics) {
      this.title = filetitle;
      this.versionFiles = files;
      this.musics = musics;
   }

   @Id
   @GeneratedValue
   @Column(name = "playoutId")
   public Long getPlayoutId() {
      return playoutId;
   }

   public void setPlayoutId(Long playoutId) {
      this.playoutId = playoutId;
   }

   public String getTitle() {
      return title;
   }

   public void setTitle(String title) {
      this.title = title;
   }

   @OneToMany
   @JoinTable(name = "PLAYOUT_FILES",
         joinColumns = { @JoinColumn (name = "playoutId")},
         inverseJoinColumns = { @JoinColumn (name = "fileId") }
   )
   public Set<File> getVersionFiles() {
      return versionFiles;
   }

   public void setVersionFiles(Set<File> versionFiles) {
      this.versionFiles = versionFiles;
   }

   @OneToMany
   @JoinTable(name = "PLAYOUT_MUSIC",
         joinColumns = { @JoinColumn (name = "playoutId") },
         inverseJoinColumns = { @JoinColumn ( name = "musicId") }
   )
   public Set<Music> getMusics() {
      return musics;
   }

   public void setMusics(Set<Music> musics) {
      this.musics = musics;
   }
}



Below file File.java

Code:
@Entity
@Table(name="FILES")
public class File implements Serializable {

   private static final long serialVersionUID = 1L;

   @Id
   @GeneratedValue
   @Column(name = "fileId")
   private Long fileId;
   private String filename;

   public File() {
   }
   
   public File(String filename) {
      this.setFilename(filename);
   }

// setters and getters for fields: fileId, filename
}


Below file Music.java

Code:
@Entity
@Table(name="MUSIC")
public class Music implements Serializable {

   private static final long serialVersionUID = 1L;

   private Long musicId;
   private String musicTitle;
   private String composer;
   private String time;
   
   public Music() {   
   }
   
   public Music(String musicTitle, String composer, String time) {
      this.musicTitle = musicTitle;
      this.composer = composer;
      this.time = time;
   }

   @Id
   @GeneratedValue
   @Column(name = "musicId")
   public Long getMusicId() {
      return musicId;
   }

   public void setMusicId(Long musicId) {
      this.musicId = musicId;
   }

// setters and getters for fields: musicTitle, composer, time

}


Best regards,
Paul


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.