Your mappings do not make any sense. You have examinee mappedBy = "person" and person mappedBy = "idPerson3". You cannot have multiple mapped by, I think you meant to define PERSON_ID as the join column?
James Sutherland wrote:
But perhaps include your schema.
This is a part of my schema. The cascade persist works on the recursive relationship but not on the other relationship.
The code was generated by Netbeans7.1, i used the 'create entity classes from database'
Oh, I see Examinee is a different class. Please include the code for it.
Where does examResults come from? Is it part of the persistence context? Is it new or existing, perhaps you need to merge it, or persist it separately.
Do you have a cyclic relationship? One of the foreign keys may need to be nullable to resolve a cycle, setting logging to finest will give some insight on what is going on.
James Sutherland wrote:
Where does examResults come from? Is it part of the persistence context? Is it new or existing, perhaps you need to merge it, or persist it separately.
I think it is coming from the same persistence context. When i persist the two entity classes together with their corresponding facades, it works, but when i try the cascade it doesn't.
How do i know if it is new or existing? the persistence context or the injected facade class?
this is the code for the injected '@EJB ExamineeFacade examResults;'
James Sutherland wrote:
Do you have a cyclic relationship? One of the foreign keys may need to be nullable to resolve a cycle, setting logging to finest will give some insight on what is going on.
I do have a cyclic/recursive relationship in the Person entity,
because of:
Person examinee;
Person father;
Person mother;
Person guardian;
If i will have the Examinee table to have the nullable foreign key, the 1 to 1 identifying relationship will be gone, thus, a examinee could have many examResults which shouldn't be.
I'll set the logging to finest, thanks for the advice.
You have "insertable = false" on the foreign key, so if you did not set your basic idPerson field value, then it will be null. You need to set the idPerson field value.
You may also want to have insertable/updatable = false on the Id and true on the OneToOne, then it will pick up the value from the reference.
You could also remove the basic idPerson and just put @Id on the OneToOne.