[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-1195) Criteria.list() not auto-flushing dirty many-to-many collection for entity used in criteria

Maik Schreiber (JIRA) noreply at atlassian.com
Fri Aug 11 10:45:19 EDT 2006


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1195?page=comments#action_23901 ] 

Maik Schreiber commented on HHH-1195:
-------------------------------------

Nice find, Pablo.

> 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
>         Type: Bug

>   Components: core
>     Versions: 3.0.5
>     Reporter: Maik Schreiber
>     Assignee: Gavin King
>  Attachments: collection-query-spaces-3.1.2.patch, collection-query-spaces.patch
>
>
> 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.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list