-->
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.  [ 1 post ] 
Author Message
 Post subject: Bi-directional OneToOne Doesn't work.
PostPosted: Tue May 29, 2012 12:15 am 
Newbie

Joined: Sat May 26, 2012 1:47 pm
Posts: 1
I am new to Hibernate and trying to get a OneToOne annotation to work. I've looked at lots of examples, other threads, and the documentation and can not figure out what I am doing wrong here. As far as I can tell mine is identical to some of the example's I've seen.


Table: loan (Owner)
Code:
id int primary key
(Other columns ommitted)


Table: loanPaymentInfo
Code:
loanId int primary key references loan(id)


Code:
@Entity
public class Loan{

   @Id
   private Long id;

   @OneToOne(cascade = CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="loan")
   @JoinColumn(name="id")
   private LoanPaymentInfo paymentInfo;

   //paymentInfo getter (no setter)
}

@Entity LoanPaymentInfo{

   @Id
   @GeneratedValue(generator="foreign")
       @GenericGenerator(name="foreign", strategy = "foreign", parameters={
            @Parameter(name="property", value="loan")
       })
   private Long loanId;
   
   @OneToOne(fetch=FetchType.LAZY)
   @PrimaryKeyJoinColumn
   private Loan loan;

   //loan getter (no setter)
}



When I create a loan and set some properties on loan and loanPaymentInfo, I get the following exception:
Code:
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.mlikesit.trading.p2p.db.entity.loan.LoanPaymentInfo#1]
   at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1950)
   at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2594)
   at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2494)
   at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2821)
   at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:113)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:185)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
   at com.mlikesit.trading.p2p.db.dao.HibernateUtil.commitTransaction(HibernateUtil.java:200)
   at com.mlikesit.trading.p2p.db.dao.HibernateUtil.inTransaction(HibernateUtil.java:228)
   at com.mlikesit.trading.p2p.db.dao.HibernateUtil.save(HibernateUtil.java:140)
   at com.mlikesit.trading.p2p.db.entity.loan.LoanTest.test(LoanTest.java:31)
   more...


Thank you in advance for any help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.