If you override equals/hashCode in MySubObject class be sure that these methods only check the surrogate key id (in such a case you should avoid them completely).
If you override equals/hashCode in MySubObject class be sure that these methods only check the surrogate key id (in such a case you should avoid them completely). If equals/hashCode methods work with some business key properties, make sure that these keys are unique before persisting.
I've tried that, but still receive the same error. I've noticed some strange behavior in testing out various things, however. If I create MyObject programmatically and set all of its properties (including subObj) it persists with no problem.
However, if I enter the properties using a form, I get the error. Could it have something to do with transactions? – Shadowman Mar 31 at 0:58 It could have to do with transactions if the form behaves like this: the first subObj get persisted with an ID from the sequence in a transaction that fails.
The consequent exception is masked and the code continues persisting the second subObj, so that it gets the same ID. – Stefano Travelli Mar 31 at 7:25 The form is part of a 2-step data submission process. On the first page, the user enters some basic info about the data they're submitting.
On the second page, they enter more detailed info, including setting properties on subObjA and subObjB. The entityManager.update() call doesn't get made until the user clicks "Submit" on the second page. That's where I see the exception, so now I'm thinking it's something related to this workflow, since I can create object programmatically with no problem.
Any idea what's going on? Things I should try? – Shadowman Mar 31 at 12:56 Not that this must be necessarily related to the duplicated key problem, but usually you don't call entityManager.update() in a conversation driven application.
If entity is persistent you update it at flush() time, otherwise you persist it with entityManager.persist(). I suggest to turn SQL logging on and see what happens with the DB during the 2 step. According to the submission process you described there shouldn't be any SQL command at step 1.
– Stefano Travelli Mar 31 at 19:43 I misspoke. I amcalling persist() when I store the data. – Shadowman Mar 317 at 15:55.
Ran through a battery of tests and different scenarios, and have found occasions when it works. So, it looks like there is a bug in my action class when I got to submit and persist to the database.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.