[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1195?page=c...
]
Gail Badner updated HHH-1195:
-----------------------------
Attachment: HHH-1195-test.patch
ManyToManyTest.java
I've updated org.hibernate.test.manytomany.ManyToManyTest to reproduce this issue in
3.2.3. I've attached both ManyToManyTest.java and a patch file for the update.
The updated test case includes tests that:
1) does a flush before executing a Criteria (succeeds)
2) does not do flush before executing a criteria (fails)
3) executes a Query instead of a Criteria (succeeds)
Gail Badner
SourceLabs -
http://www.sourcelabs.com
Dependable Open Source Systems
Criteria.list() not auto-flushing dirty many-to-many collection for
entity used in criteria
-------------------------------------------------------------------------------------------
Key: HHH-1195
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1195
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.0.5
Reporter: Maik Schreiber
Assignee: Gavin King
Attachments: collection-query-spaces-3.1.2.patch, collection-query-spaces.patch,
HHH-1195-test.patch, ManyToManyTest.java
The following code first loads up a Parent entity, then clears its "children"
collection. After that, a Criteria query is executed loading up all parents having a
specific Child - which is the child that has been removed from the collection before.
Thus, no parent should be found. However, this only works when flush()ing the session
before running the Criteria query. Without flush, it finds the parent entity which it
shouldn't.
(If you need a more "runnable" test case, I'll be happy to provide one.)
Code:
Parent parent = (Parent) session.load(Parent.class, new Integer(1));
Child child = (Child) session.load(Child.class, new Integer(1));
System.out.println("before: " + parent.getChildren().size() + " (should be
>0)");
parent.getChildren().clear();
System.out.println("after: " + parent.getChildren().size() + " (should be
=0)");
// must have flush() here for Criteria query
session.flush();
Criteria criteria = session.createCriteria(Parent.class)
.createCriteria("children")
.add(Restrictions.idEq(child.getId()));
List parents = criteria.list();
System.out.println("found " + parents.size() + " parents, should be
=0");
Mapping:
<hibernate-mapping>
<class
name="de.blizzy.test.Parent"
table="PARENT"
lazy="true">
<id
name="id"
column="parent_id"
type="java.lang.Integer"
unsaved-value="null">
<generator class="native"/>
</id>
<set
name="children"
table="PARENT_2_CHILD"
inverse="false"
lazy="true">
<key column="parent_id"/>
<many-to-many
class="de.blizzy.test.Child"
column="child_id"/>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class
name="de.blizzy.test.Child"
table="CHILD"
lazy="true">
<id
name="id"
column="child_id"
type="java.lang.Integer"
unsaved-value="null">
<generator class="native"/>
</id>
</class>
</hibernate-mapping>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira