I have searched and found similar issues, but they don't quite seem to be the same problem as
- Why am I getting this NullPointer exception?
- OneToOne Mapping with hibernate/JBoss/Seam
- ANN-613 - NPE when mappedBy property is wrong on a @OneToOne
- ANN-558 - @OneToMany(mappedBy="") can not recognize properties in parent classes
- Hibernate Users - NPE with @Id on @OneToOne
I have a few entities mapped like this:
Person
|
+--User
I want to add a new entity PersonPartDeux
with a OneToOne mapping to Person
. The resulting mapping should look something like this:
Person + PersonPartDeux
|
+--User
When I do so, a NullPointerException
is thrown while trying to load the mapping:
java.lang.NullPointerException
at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:135)
How do I specify the mapping so I can avoid this exception?
Here's my code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Person implements Serializable
{
@Id
@GeneratedValue
public Long id;
@Version
public int version = 0;
public String name;
@OneToOne(cascade = CascadeType.ALL)
@PrimaryKeyJoinColumn
public PersonPartDeux personPartDeux;
}
@Entity
public class PersonPartDeux implements Serializable
{
@Id
@GeneratedValue(generator = "person-primarykey")
@GenericGenerator(
name = "person-primarykey",
strategy = "foreign",
parameters = @Parameter(name = "property", value = "person")
)
public Long id = null;
@Version
public int version = 0;
@OneToOne(optional=false, mappedBy="person")
public Person person;
public String someText;
}
@Entity
@PrimaryKeyJoinColumn(name = "person_Id")
public class User extends Person
{
public String username;
public String password;
}
As for why I'm bothering, I need both the inheritance and the OneToOne
mapping to solve different known issues in my application.