-->
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: ¿More than one @OneToOne of same entity = problems?
PostPosted: Wed Sep 17, 2008 1:18 pm 
Newbie

Joined: Thu Jul 24, 2008 10:13 am
Posts: 17
Hibernate version: 3.2.5.ga

Hi! Currently I need to have 3 attributes of one class (Researcher) in another entity (Thesis). A code snippet:

Code:
       @Id
   @GeneratedValue(strategy=GenerationType.IDENTITY)
   @Column(name="ths_id") private Integer thesisID;

        ...

   @OneToOne(targetEntity=Researcher.class)
   @JoinColumn(name="ths_auth", referencedColumnName="rese_id")
   private Researcher author;


   
   @OneToOne(targetEntity=Researcher.class)
   @JoinColumn(name="ths_dire", referencedColumnName="rese_id")
   private Researcher director;
   
   
//   @OneToOne(targetEntity=Researcher.class)
//   @JoinColumn(name="ths_codir",referencedColumnName="rese_id", nullable=true)
//   private Researcher coDirector;   




When I display a list of researchers for each attribute in my jsp to select one and set it into the entity (I'm using SpringMVC), the behaviour of Hibernate is (in case of setting only 2 of the 3 elements):

- Insert into thesis table an entry only with one of the attributes setted, null in all other fields minus primary key).
- (submit processing in controller and invoke facade to insert entity)
- Throwned exception "identifier of an instance of es.udc.lbd.portal.model.thesis.entity.Thesis was altered from 2 to null" (for example).


¿Could be a problem the existence of 3 elements of the same entity mapped with @OneToOne? Perhaps you could propose making a collection of elements and fill it with this 3 attributes, but I need to differenciate each one from the others.

Explanation: The "roles" needed for the entities:

- Author
- Director
- CoDirector

So, due to this, the collection is not a good solution.

Can anyone help me about this?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 17, 2008 1:52 pm 
Newbie

Joined: Thu Jul 24, 2008 10:13 am
Posts: 17
I've changed the upper code like:

http://forum.hibernate.org/viewtopic.php?t=972486&start=0&postdays=0&postorder=asc

but the same situation persist. ¿Any other cause?


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.