I am very new to EJB 3.0 and JPA and while implementation i have got one issue.
In the application i have 3 table say A,B & C. B has a FK relationship with PK of A. So functionality is when i update a record in A, a new record with some more details has to be entered in B. So while enter the data in B, i have to check a user entered value in C. To achieve this i am creating a PK Object of the C to get the uniqueness.
Everything is working fine but when i am running the test cases A record is updating in A, a new Record is inserting in B & a New record is also inserted in C.
So in C i dont want to insert the record but it is going and inserting a new record.
I guess somewhere i am wrong to use cascadeType, please help me if anybody has came such scenario.
POJO for Table A
@OneToOne(cascade = CascadeType.REMOVE, mappedBy = "aId")
private B bColumn;
If you create a new object, a new object will be inserted. You need to call EntityManager.find() with the id to get the existing object C. You could also call getReference() to just get a reference to the object, which will not access the database.
brevity is the soul of wit - shakepeare. Tiny ad:
a bit of art, as a gift, that will fit in a stocking