-->
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: Composite Key
PostPosted: Wed Nov 08, 2006 11:45 am 
Newbie

Joined: Wed Nov 08, 2006 11:33 am
Posts: 2
I need help in finishing a hbm file for the following scenario:

Table: Customer
Columns: customer_id, customer_name, start_date and end_date
Primary key: customer_id, customer_name and start_date

public class Customer {
private String customerId;
private String customerName;
private DateRange dateRange;
}

public class DateRange {
private Date startDate;
private Date endDate;
}


HBM file:

<class name="Customer" table="Customer">
<composite-id>
<key-property name="customerId" column="customer_id"/>
<key-property name="customerName" column="customer_name"
</composite-id>
</class>


How do i specify start_date as part of the key?


Top
 Profile  
 
 Post subject: Re: Composite Keys
PostPosted: Thu Nov 09, 2006 8:02 am 
Newbie

Joined: Thu Nov 09, 2006 7:07 am
Posts: 2
The start date will be part of the composite-id mapping and would be done this way:

<class name="Customer" table="Customer">
<composite-id>
<key-property name="customerId" column="customer_id"/>
<key-property name="customerName" column="customer_name" />
<key-property name="start_date " column="start_date " type="timestamp"/>
</composite-id>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 09, 2006 1:20 pm 
Newbie

Joined: Wed Nov 08, 2006 11:33 am
Posts: 2
Thanks teeman7 for the response.

That is correct if start date was in customer class. In my example date's are in different class than other columns on the table, how would i do it then?


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.