-->
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: Association type?
PostPosted: Thu Oct 26, 2006 5:49 pm 
Newbie

Joined: Fri Sep 02, 2005 3:51 pm
Posts: 17
Hi,
I have a Customer object with primary key customer_id. I would like to store a record for each customer called CustomerCarrierData in a separate table. There will be only 1 CustomerCarrierData record per customer. But, instead of storing the pk of CustomerCarrierData in the Customer table, I would like to store the customer_id from Customer in the CustomerCarrierData.

When I load up a customer, I would also like to load the corresponding CustomerCarrierData object in the Customer object.

So basically, the code would look something like

Customer c = customerDAO.getCustomer(customer_id);
CustomerCarrierData cd = c.getCustomerCarrierData();

Can someone tell me what kind of association I would have to use on the Customer hibernate mapping file? This is not a many-to-one mapping as the key of the Customer object is being saved in the CustomerCarrierData table (am I wrong?).

An example would be much appreciated.

Thanks,
-Riz.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 12:06 am 
Regular
Regular

Joined: Tue Sep 26, 2006 11:37 am
Posts: 115
Location: Sacramento, CA
It seems to me that you would map as a many-to-one from CustomerCarrierData and set unique=true.

Marius


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 12:42 pm 
Newbie

Joined: Fri Sep 02, 2005 3:51 pm
Posts: 17
Thanks for the response Marius.
So it seems I can use many-to-one association to create a one-to-one

but I am having some trouble figuring this out...here is what I need to do.

1. Currently a table called Customer already exists. I want to create a table called CustomerCarrierData and generate a row for every EXISTING Customer record.

2. Everytime a new Customer is created, I want hibernate to automatically generate a CustomerCarrierRecord with the same id as the Customer record.

Here is my current Customer mapping file (only part of it), and the proposed CustomerCarrierData mapping file

Can you please tell me what the mapping should look like in both files..do I need to map anything from the CustomerCarrierData to the Customer??

Need help with this please!

Thanks,
-Riz.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.cwsi.eshipper.model">
<class name="Customer" table="customer">
<id name="id" column="customer_id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="businessName" column="name" not-null="true"/>
</class>
</hibernate-mapping>



<hibernate-mapping package="com.cwsi.eshipper.model">
<class name="CarrierData" table="carrier_data">
<id name="customerId" column="customer_id">
<generator class="foreign">
<param name="property">customer</param>
</generator>
</id>

<property name="fedexAcctNum" column="fedex_acct_num"/>
<property name="fedexMeterNum" column="fedex_meter_num"/>
<!--<property name="customerId" column="customer_id"/> -->
<property name="dateCreated" column="date_created" type="java.util.Date"/>

<one-to-one name="customer"
class="com.cwsi.eshipper.model.Customer"
constrained="true"
/>

</class>
</hibernate-mapping>


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.