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