-->
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: Insert new entity which inherites from another entity....
PostPosted: Fri Oct 10, 2008 12:11 pm 
Newbie

Joined: Fri Oct 10, 2008 11:48 am
Posts: 3
Hi guys,

may I ask a question about inserting of the entity which inherits from the master entity? I'm completely new to hibernate, so I apologize, if my question will be silly..:-)...However, I have this scenario...



Code:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
class Person implements Serializable {

private String id;

private String name;

private String surname;

public Person (Person person) {
     copy constructor....save all properties...
}
// settrs, gettrs
}


From this entity inherits another entity

Code:
@Entity
@PrimaryKeyJoinColumn(name = "id")
class OtherUser extends Person {

private Date validity;

public OtherUser ( Person person ) {
   super(person);
   this.validity = ....
}
// settrs, gettrs
}


Now I want to create new entity instance of OtherUser from an existing instance of Person....something like this..

Code:
Person person = .....process which returns Person instance
OtherUser user = new OtherUser (person);
hibernatteSession.persist (user);


But when I tried my code, hibernate told me that he's not able to bind instance of OtherUser with Person, 'cause he didn't find a key of the Person instance. Please what I'm doing wrong? Do you have an example, which would illustrate how can I achieve this goal?

many thanks in advance

new hibernate user

Tomas


[/code]


Top
 Profile  
 
 Post subject: ??????
PostPosted: Mon Oct 13, 2008 10:03 am 
Newbie

Joined: Fri Oct 10, 2008 11:48 am
Posts: 3
??????...:-(((((

I changed my classes to...

Code:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Person implements Serializable {
    // entities, which I want to inherit in OtherUser
}

@Entity
@SecondaryTable(name = "OTHER_USER", pkJoinColumns = @PrimaryKeyJoinColumn(name = "PERSON_ID"))
public class OtherUser extends Person {

    private Date validity;

}


And I really need ONE SIMPLE THING...Previously mentioned classes created two tables, connected via Foreign key Person.ID = OtherUser.PERSON_ID. Now I need to create new entity instance of OtherUser, which would inherit property values from one concrete instance of Person. I know ID of this master entity instance, but I have absolutely no idea howto bind new instance of OtherUser(subentity) to an existing instance(master entity) of Person ?????

Something like this:

OtherUser os = new OtherUser(); // subentity
os.setBindingToPerson( <ID of master entity> );
sessio.persist(os);

Hibernate doesn't allow me to set PERSON_ID column in OtherUser, why?...:-(((




[/code]


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.