Hibernate version:3.2.3.ga
I have 3 classes A,B and C. B and C have only id's. A has pk which is a composite key AId and it's made from id's of B and C, and there are OneToOne relations from A to B and from A to C
this is the code:
Code:
@Entity
public class A implements Serializable{
@EmbeddedId
AId aId;
}
@Embeddable
public class AId implements Serializable{
@OneToOne
@JoinColumn(name="id")
B b;
@OneToOne
@JoinColumn(name="id")
C c;
}
@Entity
public class B {
@Id@GeneratedValue
private Long id;
}
@Entity
public class C {
@Id@GeneratedValue
private Long id;
}
When i try to run this i got:
Code:
[java] Initial SessionFactory creation failed.java.lang.NullPointerException
[java] Exception in thread "main" java.lang.ExceptionInInitializerError
[java] at util.HibernateUtil.<clinit>(Unknown Source)
[java] at one.Start.main(Unknown Source)
[java] Caused by: java.lang.NullPointerException
[java] at org.hibernate.cfg.AnnotationBinder.bindOneToOne(AnnotationBinder.java:1960)
[java] at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1346)
[java] at org.hibernate.cfg.AnnotationBinder.fillComponent(AnnotationBinder.java:1731)
[java] at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:1768)
[java] at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1229)
[java] at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:733)
[java] at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:498)
[java] at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:277)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
[java] at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
[java] ... 2 more
Where Start is the class which I run and it just get the session
I've searched for solution but i couldn't find anything helpful
the only solution i could think of is to do it without composite key and then it works, but it isn't exactly what i wanted
Can you tell me what am I doing wrong with this OneToOne relation using composite key?