-->
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: One to one mapping of composite key columns
PostPosted: Thu Jun 23, 2011 6:27 am 
Newbie

Joined: Thu Jun 23, 2011 5:08 am
Posts: 9
We have a one to one relationship between two tables - VIN and VIN_EXTENSION over a composite key columns VIN and CUSTOMER & EX_VIN and EX_CUSTOMER respectively.
Below is the code snippet of the relationship.

Code:
@Entity
@Table(name = "VIN")
public class Vin implements Serializable {
   @EmbeddedId
   private VinKey vinKey;
}

Code:
@Embeddable
public class VinKey implements Serializable {
   @OneToOne(targetEntity = VinExtension.class, fetch = FetchType.LAZY)
   @JoinColumns(value = {
         @JoinColumn(name = "CUSTOMER", referencedColumnName = "EX_CUSTOMER"),
         @JoinColumn(name = "VIN", referencedColumnName = "EX_VIN") })
   private VinExtension vinExtension;
}

Code:
@Entity
@Table(name = "VIN_EXTENSION")
public class VinExtension implements Serializable {
   @EmbeddedId
   private VinExtensionKey vinExtensionKey;
}

Code:
@Embeddable
public class VinExtensionKey implements Serializable {
   @Column(name = "EX_CUSTOMER")
   private String customer;
   @Column(name = "EX_VIN")
   private String vin;
}


When hibernate fetches the data for Vin entity, it runs two different set of queries.
One fetches from VIN and series of queries to VIN_EXTENSION.
SELECT * FROM VIN
SELECT * FROM VIN_EXTENSION WHERE EX_CUSTOMER = ? AND EX_VIN = ?
SELECT * FROM VIN_EXTENSION WHERE EX_CUSTOMER = ? AND EX_VIN = ?
SELECT * FROM VIN_EXTENSION WHERE EX_CUSTOMER = ? AND EX_VIN = ?
..

I want hibernate to fetch the data using a normal join between VIN and VIN_EXTENSION.
Am i missing anything in the mapping?
Even though i have specified a lazy fetch type, the data from VIN_EXTENSION is always fetched.


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.