• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

JPA2.0 CascadeType.ALL doesn't cascade persist

 
Ranch Hand
Posts: 36
jQuery Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following code which doesn't cascade persist




Line 9-11 cascades ok but when it reaches line 12 it causes an error.


Person.java


Examinee.java


And I'm getting the following stack trace
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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?

But perhaps include your schema.
 
Jelo Nehuptra
Ranch Hand
Posts: 36
jQuery Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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'
sis.png
[Thumbnail for sis.png]
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jelo Nehuptra
Ranch Hand
Posts: 36
jQuery Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is the code for the examinee class

 
Jelo Nehuptra
Ranch Hand
Posts: 36
jQuery Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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;'


And the '@EJB PersonFacade person;'

 
Jelo Nehuptra
Ranch Hand
Posts: 36
jQuery Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic