-->
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.  [ 2 posts ] 
Author Message
 Post subject: Annotations multiple Entrys on DB while merging
PostPosted: Wed Nov 26, 2008 8:45 am 
Newbie

Joined: Fri Aug 15, 2008 7:18 am
Posts: 5
Hibernate version:
Hibernate 3.2.6
Hibernate Annotations 3.3.1.GA
Hibernate EntityManager 3.3.2.GA

Name and version of the database you are using:
PostGreSQL Database Server 8.3

Hello,

i prepared a rather complex Entitystructure and annotated each entity (hopefully) correctla with the following Annotations on the Getter-Methods of the objects:

Code:
  @OneToOne(cascade={CascadeType.ALL})
     @OnDelete(action=OnDeleteAction.CASCADE)   


the lists i use are annotated this way:

Code:
  @OneToMany(cascade={CascadeType.ALL})   



when i now EntityManager em.merge() the root object the merge run is completed sucessfully, but if i have a look at the databse after this, there are multiple entrys for objects that are equal. Just the id is different.

SmallExample:
Child class:
Code:
@Entity
public class DialTime {
...(some payload)
   private Long id;

   @Id@GeneratedValue
   public Long getId() {
      return id;
   }

   private void setId(Long id) {
      this.id = id;
   }



Parent class:
Code:
@Entity
public class DialDate{
....
       private DialTime dialTime;
   private Long id;

      public DialDate(){
         dialTime= new DialTime();
       }
   @Id @GeneratedValue
   public Long getId() {
      return id;
   }

        @OneToOne(cascade={CascadeType.ALL})
   @OnDelete(action=OnDeleteAction.CASCADE)
   public DialTime getDialTime() {
      return dialTime;
   }


if i than em.merge(new DialDate())
with several dates there are some entrys in the DB-Table in PostGreSQL with show equal DialTime and even equal DialDate enrys only differing by the id column.

Is there a way to avoid this and only persist Instances that vary in other values than simply the id?
Or should i not instnciate "empty" objects?
As i undestood from reading the merge() does look if there is already a object fitting and replacing the foreign key as needed...

thanx for the help(and sorry for bad english)
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2008 5:30 am 
Newbie

Joined: Fri Aug 15, 2008 7:18 am
Posts: 5
The Problem sems to be the id's i give the objects.
The comparisons are made for the id's but i mostly have not givven id's to every object. So the comparison fails and a new object is generated and saved.

Except this the annotations are to be @ManyToMany..

As a workaround i will take other id's that will tell if objects are to be considered same and not saved seperatly.
This is not exactly what i imagined, but it seems there is no other way excet looking if an object with same specifications is already in the DB and taking that objects id. That would render the cascading useless and would lead to a lot of work in a complex object enviroment.

Now the Question is: How can i automaticly assign Values to the is column in DB that are Table unique?
I played a bit with the @GeneratedValue, but this seems to work only for id columns.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.