-->
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: Reverse One to One Relation with shared primary key issue
PostPosted: Wed Nov 23, 2011 12:22 am 
Newbie

Joined: Wed Nov 23, 2011 12:03 am
Posts: 1
Hello,

I'm using hibernate-3.2.4.sp1 with hibernate-annotations-3.2.1.ga and I keep running into the same problem.

Here are my tables:
WWS_Batch {
- objectid (PK)
...
}

WWS_BatchStatus {
- batchID (PK, FK(wws_batch.objectid))
...
}

I define the classes as follows:
Code:
@Entity
@Table(name="wws_batch")
public class Batch implements Serializable{
      
   @OneToOne(mappedBy="batch", cascade=CascadeType.ALL)
   @Fetch(FetchMode.JOIN)
   private BatchStatus status;

// setters/getters
}


Code:
@Entity
@Table(name="wws_batchstatus")
public class BatchStatus implements Serializable {
   
   @Id
   private Long batchID;
   
   @OneToOne(cascade = CascadeType.ALL)
   @JoinColumn(name="batchID", referencedColumnName="objectID", updatable=false, insertable=false)
   private Batch batch;
// setters/getters
}


The exception that I get:
Caused by: java.lang.NullPointerException
at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:135)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1130)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:296)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:673)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1368)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1334)

After debugging I realized that the error happens because property "batch" of BatchStatus cannot be found. I've looked all over the place and everyone suggests the same fix which I believe I've implemented above. I tried almost every permutation out there and this works just fine with an exact ManyToOne scenario except that that the target table has a composite key composed of the source table pk and it own identifier.

Any thoughts?

Thanks!

Zoran


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.