-->
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: How to update a @OneToOne relation?
PostPosted: Thu Oct 01, 2009 3:27 am 
Regular
Regular

Joined: Thu Jun 08, 2006 5:32 pm
Posts: 52
Hi,
I have the following probleme:
I have an entity "Contact" which have two @OneToOne relations to an entity "Address". If I perform an update on the contact entity only the "simple properties" of type "String, Integer, Boolean, and so on) will be updated. The properties with an relation (@OneToOne for example) are not updated on transaction.commit() and manager.close(). The Update is only visible if I restart my application. Here the related code:
Code:
@javax.persistence.Entity
public class Contact {
   // ...
   private String firstName;
   
   @OneToOne(cascade = CascadeType.ALL, optional = true, fetch = FetchType.LAZY)
   private Address privateAddress;

   @OneToOne(cascade = CascadeType.ALL, optional = true, fetch = FetchType.LAZY)
   private Address commercialAddress;
   // ...


The update looks like this:
Code:
final Contact contact = ...
final EntityManager manager = factory.createEntityManager();

contact.setFirstName("NEW FIRST NAME"); // updated after commit
contact.getPrivateAddress().setStreet("NEW_STREET"); // not updated after commit

manager.getTransaction().begin();
manager.getTransaction().commit();
manager.close();


Does someone knows an solution?

Thanks :)

Best regards
QStorm

_________________
http://nocxsville.myminicity.com/


Top
 Profile  
 
 Post subject: Re: How to update a @OneToOne relation?
PostPosted: Thu Oct 01, 2009 10:49 am 
Regular
Regular

Joined: Thu Jun 08, 2006 5:32 pm
Posts: 52
Hi,
A update:
The address is updated in the database. I found the root causes of my issue. The @EntityListeners(...) of the contact entity will not be informed if a related entity has been changed (only if a own property has been changed). Is there a acceptable (automatic) way to in form the @EntityListeners of the contact entity if one related entity (address for example) has been changed?

/edit
My current (quite bad) solution is do disable the entity listener and to notifiy the entity listener manually. Is there a better way?
edit/
Thanks & best regards
QStorm

_________________
http://nocxsville.myminicity.com/


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.