|
Re: Problems retrieving a joined entity object [message #779768 is a reply to message #778767] |
Mon, 16 January 2012 14:17 |
Chris Delahunt Messages: 1389 Registered: July 2009 |
Senior Member |
|
|
Hello,
Yes, you have to call b.setA(a) for the relationship to be maintained. JPA allows for caching to maintain object identity, which needs to be kept in synch with what is in the database or you must force a refresh to see the data.
The code you posted though is incorrect for what you mention you want. B's aId field uses database field "A_ID" while its a attribute uses "AID" as the foreign key. They are different, so calling setAId(1) will not change the foreign key in the database. If this was not a post cut and paste error, both mappings should use the same field, and one of them should be marked as insertable=false, updatable=false, so that the JPA provider can tell which of them controls the field or you will get an exception. You will still need to set the relationship (and/or the basic mapping) or refresh the object when the transaction completes to see the object as it is in the database.
Best Regards,
Chris
|
|
|
Re: Problems retrieving a joined entity object [message #779770 is a reply to message #778767] |
Mon, 16 January 2012 14:17 |
Chris Delahunt Messages: 1389 Registered: July 2009 |
Senior Member |
|
|
Hello,
Yes, you have to call b.setA(a) for the relationship to be maintained. JPA allows for caching to maintain object identity, which needs to be kept in synch with what is in the database or you must force a refresh to see the data.
The code you posted though is incorrect for what you mention you want. B's aId field uses database field "A_ID" while its a attribute uses "AID" as the foreign key. They are different, so calling setAId(1) will not change the foreign key in the database. If this was not a post cut and paste error, both mappings should use the same field, and one of them should be marked as insertable=false, updatable=false, so that the JPA provider can tell which of them controls the field or you will get an exception. You will still need to set the relationship (and/or the basic mapping) or refresh the object when the transaction completes to see the object as it is in the database.
Best Regards,
Chris
|
|
|
Powered by
FUDForum. Page generated in 0.03290 seconds