-->
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: JPA Composite Key
PostPosted: Fri Aug 05, 2011 10:06 am 
Newbie

Joined: Fri Aug 05, 2011 10:04 am
Posts: 2
I have a Table A , Table AB , TABLE B , Table AB has foreign key references to Table A and Table B. There is a One to One relation between Table A and Table AB.and Many to one between Table B and Table AB.

My question is if i am saving domain for table B, it is saving data in table AB but not in A Please let me know if this is the expected behavior or can i save all data in all other tables just by calling save on Object B

Class A
{
@OneToOne(mappedBy="abpk.a")
@Cascade({ org.hibernate.annotations.CascadeType.ALL,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
private AB ab;
}

@Entity
@AssociationOverrides({
@AssociationOverride(name = "abpk.a", joinColumns = @JoinColumn(name = "colA", referencedColumnName = "colA")),
@AssociationOverride(name = "abpk.b", joinColumns = @JoinColumn(name = "Colb", referencedColumnName = "colB")) })
Class AB
{
ABPK abpk = new ABPK();
A a;
B b;

//inner class
class ABPK
{
A a;
B b;

@OneToOne(fetch = FetchType.LAZY)
@Cascade({ org.hibernate.annotations.CascadeType.ALL,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
@JoinColumn(name="b")
//Getter for A
GetA();

@ManyToOne(fetch = FetchType.LAZY)
//Getter for B
GetB();
}
}

Class B
{
@OneToMany(fetch = FetchType.LAZY, mappedBy = "abpk.b")
@Cascade({ org.hibernate.annotations.CascadeType.ALL,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
private List<AB> abList;
}


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.