hi all,
I'm experiencing a very weird problem.
I have an Object Project which contains a set of Deliverables:
Code:
<set name="deliverables" table="PROJECT_DELIVERABLES" lazy="true" cascade="all" optimistic-lock="false">
<key column="PROJECT_ID" />
<many-to-many column="DELIVERABLE_ID" unique="true" class="Deliverable"/>
</set>
The Deliverable object is nothing special; it contains some properties, one of them being number:
Code:
<property name="number" unique="false" not-null="true" />
As you see, number is not unique but within a project it should be unique so I generate it in my code; because of an error in this code this however was not the case and this lead to discovering the very strange problem:
following scenario works like a charm:
1. add Deliverable with number 1
2. add Deliverable with number 2
3. add Deliverable with number 3
4. remove Deliverable with number 3
5. add Deliverable with number 3
for steps 1, 2, 3 and 5 an insert is done into PROJECT_DELIVERABLES; for step 4 a delete is done.
However, when, instead of removing Deliverable with number 3 (step 4), I remove Deliverable with number 1 and then a create a new Deliverable it gets number 3 (because of code-error). A new Deliverable is inserted into table DELIVERABLES but
nothing is inserted into PROJECT_DELIVERABLES!
If this isn't weird enough: when I fix the code-error and generate a correct (unique) number it does work!
Code with the bug and hence behaving weird:
Code:
deliverable.setNumber(String.valueOf(project.getDeliverables().size() + 1));
project.getDeliverables().add(deliverable);
projectDAO.update(project);
code with a dirty quick fix and working fine:
Code:
deliverable.setNumber(String.valueOf(System.currentTimeMillis()));
project.getDeliverables().add(deliverable);
projectDAO.update(project);
I really hope this rings a bell with someone because I really don't understand why using the same number twice causes this kind of behavior (if that's is indeed the cause)!
many thanks,
Stijn