-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate: one-to-one Different Composite Keys
PostPosted: Fri Mar 20, 2009 10:58 am 
Beginner
Beginner

Joined: Wed Aug 22, 2007 5:53 am
Posts: 38
I have 2 classes viz. Product and ProductBasic

Code:
class Product{
  String productId;
  ProductBasic productBasic;
  }
 
  class ProductBasic{
   String productId;
   String useType;
   TimeStamp startTimeStamp;
 
   Product product;
  }


Product is mapped to a table PRODUCT which has PRODUCTID as PK.
ProductBasic is mapped to a table PRODUCTBASIC which has PRODUCTID,USETYPE and STARTTTIMESTAMP as composite key. Also PRODUCTID
is the foreign key referencing PRODUCT table...

How can i define my one-to-one mapping considering ProductBasic.productId should get its value from Product.productId


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 3:29 pm 
Regular
Regular

Joined: Mon Jan 05, 2009 6:42 pm
Posts: 99
Location: IL
have you tried some thing like this:-

Code:
<hibernate-mapping>
<class name="com.xy.db.ProductBasic" table="PRODUCTBASIC">
        <composite-id name="id" class="com.xy.db.ProductBasicCompsite">
           
            <one-to-one name="prodcutId" column="PRODUCTID" class="com.xy.db.Product" not-null="true"/>
           
            <key-property name="usetype" type="java.lang.String">
                  <column name="PROCESS_ID" length="16" />
            </key-property>
           
            <key-property name="STARTTTIMESTAMP" type="java.lang.String">
               <column name="STARTTTIMESTAMP" length="16" />
           </key-property>
                       
        </composite-id>

....
    </class>
</hibernate-mapping>


Code:
public class ProductBasicCompsite implements Serializable
{
  public BigDecimal prodcutId = null;
  public String usetype = null;
  public String STARTTTIMESTAMP=null;
..setters and getters
override toString, hashcode,equals
}


Top
 Profile  
 
 Post subject: Re: Hibernate: one-to-one Different Composite Keys
PostPosted: Mon May 25, 2009 1:48 am 
Beginner
Beginner

Joined: Wed Aug 22, 2007 5:53 am
Posts: 38
but in this mapping we have not specified that "ProductBasic.productId should get its value from Product.productId"


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