-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: very strange problem: association insert is not executed
PostPosted: Wed Aug 22, 2007 9:19 am 
Beginner
Beginner

Joined: Mon Nov 13, 2006 8:22 am
Posts: 28
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


Top
 Profile  
 
 Post subject: again
PostPosted: Wed Aug 22, 2007 11:25 am 
Beginner
Beginner

Joined: Mon Nov 13, 2006 8:22 am
Posts: 28
Similar problem but maybe a bit easier to understand:

Project has following set:
Code:
<set name="todos" lazy="true" cascade="all" order-by="deadline DESC" optimistic-lock="false">
   <key column="PROJECT_ID" />
   <one-to-many class="ToDo" />
</set>


Todo-config:
Code:
<class name="ToDo" table="TO_DO">
   <id name="ID" column="TODO_ID">
      <generator class="native" />
   </id>
   <property name="description" unique="false" not-null="true" />
                ...
   <many-to-one name="responsible" class="User"
      update="true" insert="true" unique="false" lazy="false" not-null="true"/>
   <many-to-one name="statusUser" class="User" column="status_user"
      update="true" insert="true" unique="false" lazy="false" not-null="true"/>

</class>


I have following code to add a new ToDo:
Code:
ToDo todo = new ToDo();
todo.setDescription(description);
Project p = projectService.getProject(projectID);
p.getTodos().add(todo);
projectService.updateProject(p);


If I want to add a ToDo with a certain description and the project already contains a ToDo with such a description simply nothing happens meaning: no error or warning but also no insert. If the ToDo has a new (unique) description it's inserted just fine!

Am I going crazy????

tx,
Stijn


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.