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

Pablo Ilardi (JIRA) noreply at atlassian.com
Fri Aug 11 10:36:19 EDT 2006


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

Pablo Ilardi commented on HHH-1195:
-----------------------------------

Hi guys, I tried this patch in my Application, and it introduces a new bug;

When I create a criteria for a subclass, where it super class has a collection mapped, it fails on flushing the changes cause it uses the sub class in the collection role; So the collection role is not found.

I changed this lines in the patch:

                   if (type.isCollectionType()) {
                        String role = entityName + "." + componentPath;
                        result.addAll(Arrays.asList(
                                sessionFactory.getCollectionPersister(role).getCollectionSpaces()));
                    }

by this lines:

                    if (type.isCollectionType()) {
                        String role = CollectionType.class.cast(type).getRole();
                        result.addAll(Arrays.asList(sessionFactory.getCollectionPersister(role).getCollectionSpaces()));
                    }

and everything works fine for now.

Regards, 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