-->
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.  [ 6 posts ] 
Author Message
 Post subject: Not able to persist data using @AssociationTable
PostPosted: Tue Oct 25, 2005 3:12 am 
Beginner
Beginner

Joined: Tue Aug 09, 2005 1:34 am
Posts: 26
Location: Bangalore
Hi,

Not able to persist data using @AssociationTable in the database using
CascadeType.PERSIST

I am using the following code : -

Code:
@OneToMany(cascade={CascadeType.PERSIST}, fetch=FetchType.EAGER)
   @AssociationTable(
         table=@Table(name="ShowAssets"),
         joinColumns = { @JoinColumn( name="showid") },
         inverseJoinColumns = @JoinColumn( name="id")
   )
   @IndexColumn(name ="showassetid")
   @Type( type = "com.spogger.model.ShowAssets")
   public Set <AudioFile> getAudioAssets() {
      return audioAssets;
   }


public void setAudioAssets(Set <AudioFile> audioAssets) {
   this.audioAssets = audioAssets;
}


In the following code i also tried using

targetEntity="com.spogger.model.ShowAssets",
cascade={CascadeType.ALL, CascadeType.MERGE},
fetch=FetchType.EAGER)

but this is also not working I am not able to persist.

What should I do I tried each and every attribute for CascadeType but all went in vain.

I have a default Constructor in my ShowAssets and even I have defined Entity for the ShowAssets object.

Can anybody sugggest what is the problem....
should I go 4 trial and error approach but most of which i have already done....
r should i insert the data again in the tables will that work......

Pls.. pls.... help me ....
I am in desperate need to do something here.............

Thanks in Advance......

Hoping a very quick solution for the problem........


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 1:35 am 
Newbie

Joined: Tue Sep 13, 2005 10:57 pm
Posts: 10
hi,
from
3.1beta3 (24-06-2005)
-----------------------------
* Rename @AssociationTable to @JoinTable
maybe you want check out your hibernate version.
and maybe you want use ejb persistence annotations.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 5:58 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Follow the bullet point template when posting, it helps everybody including you

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 8:30 am 
Newbie

Joined: Tue Sep 13, 2005 10:57 pm
Posts: 10
Yes, I should make my state more clear and accurate.
Thank you.


Top
 Profile  
 
 Post subject: Not able to persist data using @JoinTable in the data
PostPosted: Fri Oct 28, 2005 3:21 am 
Beginner
Beginner

Joined: Tue Aug 09, 2005 1:34 am
Posts: 26
Location: Bangalore
Hi Everybody,

I have tried using the @JoinTable but even this does not work.

Code:
@OneToMany(cascade={CascadeType.PERSIST}, fetch=FetchType.EAGER)
   @JoinTable(
         table=@Table(name="ShowAssets"),
         joinColumns = { @JoinColumn( name="showid") },
         inverseJoinColumns = @JoinColumn( name="id")
   )
   @IndexColumn(name ="showassetid")
   public Set <AudioFile> getAudioAssets() {
      return audioAssets;
   }


public void setAudioAssets(Set <AudioFile> audioAssets) {
   this.audioAssets = audioAssets;
}


Well can anybody suggest how the OneToMany mechanism works at the Database level.
    Is is that the record is automatically inserted into the JoinTable as soon as the records in the Mapped Tables
    Is is that we have to explicitly insert the record

One more thing is that.
I am using Single Table Per Class Hierarchy and I am mapping to the Child object reference for the Multiplicity.

Can somebody please suggest how to achieve this...???

I have tried using all the CascadeType attributes but all the effort went in vain.

Thanks In Advance,
Manjith Kumar.
[/list][/code]


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 29, 2005 5:12 am 
Newbie

Joined: Tue Sep 13, 2005 10:57 pm
Posts: 10
Hi, you can refer to hibernate_reference.pdf, Chapter 21. Example: Parent/Child, that can help you.
If you don't want explicit send save child method, it seems that you must use CascadeType.ALL in relationship annotation.
Code:
@Entity
public class AudioAsset extends BaseEntity {
   private Set<AudioFile> audioAssets=new HashSet<AudioFile>();

   @OneToMany(cascade = { CascadeType.ALL}, fetch = FetchType.EAGER)
   @JoinTable(table = @Table(name = "ShowAssets"), joinColumns = { @JoinColumn(name = "showid") }, inverseJoinColumns = @JoinColumn(name = "id"))
   @IndexColumn(name = "showassetid")
   public Set<AudioFile> getAudioAssets() {
      return audioAssets;
   }

   public void setAudioAssets(Set<AudioFile> audioAssets) {
      this.audioAssets = audioAssets;
   }
}

Code:
@Entity
public class AudioFile extends BaseEntity{
   private String name;

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }
}

Code:
@EmbeddableSuperclass
public class BaseEntity {
   private int id;

   private int version;

   @Id(generate=GeneratorType.AUTO)
   public int getId() {
      return id;
   }

   public void setId(int id) {
      this.id = id;
   }

   @Version
   public int getVersion() {
      return version;
   }

   public void setVersion(int version) {
      this.version = version;
   }
}
public static void main(String[] args) {
      SessionFactory sf = new AnnotationConfiguration().addAnnotatedClass(
            BaseEntity.class).addAnnotatedClass(AudioFile.class)
            .addAnnotatedClass(AudioAsset.class).buildSessionFactory();
      Session s;
      Transaction tx;
      s = sf.openSession();
      tx = s.beginTransaction();
      AudioAsset aa = new AudioAsset();
      AudioFile a = new AudioFile();
      a.setName("beautiful lily");
      aa.getAudioAssets().add(a);
      s.save(aa);
      tx.commit();
      s.close();
      sf.close();
   }

You can see this console ouput if property hibernate.show_sql=true:
Hibernate: insert into AudioAsset (version, id) values (?, null)
Hibernate: call identity()
Hibernate: insert into AudioFile (version, name, id) values (?, ?, null)
Hibernate: call identity()
Hibernate: insert into ShowAssets (showid, id) values (?, ?)


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

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.