-->
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: Hibernate -One to many relationship
PostPosted: Wed Aug 06, 2014 6:32 am 
Newbie

Joined: Thu Mar 21, 2013 8:38 am
Posts: 1
Hi

I have 3 entities(EntityA,EntityB,EntityC).

EntitiyA has a composite primary key (id,version,instance)
EntitiyC has a composite primary key (id,version,instance)

EntitiyB has a composite primary key of the other two entities (EntitiyA .id,EntitiyA .version,EntitiyC.id ,EntitiyC .version,EntityB.version);

So entityB has composite primary key pointing to 2 entities.Also it has its own column (EntityB.version) as part of the same composite primary key.

I tried like this on entityA:
@OneToMany(mappedBy = "entityA", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<EntitiyA > entityList = new ArrayList<EntitiyA >();

On EntityB:
It is manytoOne relationship from EntityB to EntityA
@ManyToOne
@JoinColumns({
@JoinColumn(name="id", referencedColumnName ="id", insertable=false, updatable=false),
@JoinColumn(name="version", referencedColumnName ="version", insertable=false, updatable=false)
})
private EntitiyA entityA;

It is a onetoone relationship from entityB to entityC
@OneToOne(fetch=FetchType.EAGER)
@JoinColumns({
@JoinColumn(name="id", referencedColumnName="id", insertable=false, updatable=false),
@JoinColumn(name="version", insertable=false, referencedColumnName="version", updatable=false)
})


But it give me mapping error.It asks me that all primary key should be part of foreign key.

Please help.


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.