-->
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.  [ 2 posts ] 
Author Message
 Post subject: one-to-one mapping
PostPosted: Mon Dec 22, 2003 6:38 pm 
Newbie

Joined: Mon Dec 22, 2003 6:21 pm
Posts: 1
I have two classes Customer (1 <----> 1) CreditCard.
// works fine
Code:
Customer c = new Customer(..);
CreditCard cr = new CreditCard(..);
c.setCard(cr);
cr.setCustomer(c);
session.store(c);


// does not work
Afterwards If i want to set new Card for the customer
Code:
Customer c = findCustomerById(...);
CreditCard card = new CreditCard(...);
c.setCard(card);
card.setCustomer(c);
session.store(c);


there is a exception that java.sql.BatchUpdateException: Invalid argument value, message from server: "Duplicate entry '1' for key 1"

xml Mapping for corresponding elements..
card to customer
<one-to-one
name="customer"
class="rrr.titan.entity.Customer"
cascade="all"
/>

customer to card
<one-to-one
name="creditCard"
class="rrr.titan.entity.CreditCard"
cascade="all"
outer-join="auto"
constrained="false"
/>


I tried modifying generator class for CreditCard id to foriegn it did not solve the problem.

My Question is how to update 1 <----> 1 relations ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 8:04 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
primary keys of one-to-one related classes must have the same value (same PK)
It seems that you already have an existing CreditCard with id of Customer. and ask Hibernate to insert it like a new one.
Read it and update it or delete it an create it.

_________________
Emmanuel


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