-->
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.  [ 9 posts ] 
Author Message
 Post subject: Unidirectional mapping with composite primary keys
PostPosted: Thu Mar 12, 2009 1:36 am 
Beginner
Beginner

Joined: Tue Mar 10, 2009 11:50 pm
Posts: 23
I have a BundleVO class which needs one-to-Many unidirectional association with ServiceDetailsVO class. ServiceDetailsVO contains composite primary key, one of the key being supplied from other model object

When i give the below association in BundleVO

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name="Bundle_Id", nullable = false)
public Set<ServiceDetailsVO> getServiceDetails() {
return this.serviceDetails;
}


It throws me the exception
Caused by: org.hibernate.MappingException: Unable to find column with logical name: Bundle_Id in service_details


ServiceDetailsVO

Entity
@Table(name = "service_details")
public class ServiceDetailsVO implements java.io.Serializable {

private ServiceDetailsId id;

//Other fields


}

@Embeddable
public class ServiceDetailsId implements java.io.Serializable {

//Other model object giving one of the composite id
private ServiceModelVO serviceModel;

// No reference to BundleVO - i dont want to retain this bi-directional relationship with bundle
//private BundleVO bundle;
}

Please let me know how to provide the mappings in such a way that unidirectional for object with composite key is achieved


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 12, 2009 5:47 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Did you configure hibernate to build the schema, like <property name="hbm2ddl.auto">create</property>?

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 12, 2009 6:05 am 
Beginner
Beginner

Joined: Tue Mar 10, 2009 11:50 pm
Posts: 23
Hi,

Yes i did reverse engineering from my DDL to generate the java POJO's using hibernate tools. But it adds bi-directional relationship everywhere between the entities, i had to go and manually remove them.

In this case also it generated bi-directional relationship b/w Bundle to ServiceDetails and Service_Details to Bundle


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 12, 2009 6:33 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
So hbm2ddl.auto is now set to validate? How did you remove the bidirectionality and why? I guess you removed "mappedBy" and added a JoinColumn? If yes, did you use the right column name for JoinColumn?

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 12, 2009 6:35 am 
Beginner
Beginner

Joined: Tue Mar 10, 2009 11:50 pm
Posts: 23
Hi, thanks for the reply.

Yes i did use the right join column name. In my case Bundle_Id


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 12, 2009 6:59 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
Is the column Bundle_Id present in table service_details?

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 12, 2009 10:00 am 
Beginner
Beginner

Joined: Tue Mar 10, 2009 11:50 pm
Posts: 23
Yes it is present in Service_Details table. But in my ServiceDetailsVO (java object) i dont want to have any reference to BundleVO or bundleId


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 13, 2009 3:03 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
Its fine. You dont need to have reference to BundleVO in ServiceDetailsVO. Thats not the issue. There is some mistake in the mapping itself. Can you post the complete mapping of the three classes?

Also check if you have mentioned bundle_id any where else.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 13, 2009 3:56 am 
Beginner
Beginner

Joined: Tue Mar 10, 2009 11:50 pm
Posts: 23
Hi littypreethkr,

There you go again, problem solved.

I had left a bundleId mapping in the ID declaration of ServiceDetails, even though i had removed from the ServiceDetailsId. Thank you for pointing it out.

@AttributeOverrides( {
@AttributeOverride(name = "serviceId", column = @Column(name = "Service_Id", nullable = false)),
@AttributeOverride(name = "bundleId", column = @Column(name = "Bundle_Id", nullable = false)) })
public ServiceDetailsId getId() {
return this.id;
}


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