mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-18 17:15:02 +00:00
HHH-12875 : Class level where="..." clause in hbm.xml mappings is not enforced on collections of that class
This commit is contained in:
parent
eef8974877
commit
10826d8f3a
@ -3494,7 +3494,20 @@ public Identifier determineImplicitName(final LocalMetadataBuildingContext conte
|
|||||||
|
|
||||||
getCollectionBinding().setElement( elementBinding );
|
getCollectionBinding().setElement( elementBinding );
|
||||||
|
|
||||||
getCollectionBinding().setManyToManyWhere( elementSource.getWhere() );
|
final StringBuilder whereBuffer = new StringBuilder();
|
||||||
|
final PersistentClass referencedEntityBinding = mappingDocument.getMetadataCollector()
|
||||||
|
.getEntityBinding( elementSource.getReferencedEntityName() );
|
||||||
|
if ( StringHelper.isNotEmpty( referencedEntityBinding.getWhere() ) ) {
|
||||||
|
whereBuffer.append( referencedEntityBinding.getWhere() );
|
||||||
|
}
|
||||||
|
if ( StringHelper.isNotEmpty( elementSource.getWhere() ) ) {
|
||||||
|
if ( whereBuffer.length() > 0 ) {
|
||||||
|
whereBuffer.append( " and " );
|
||||||
|
}
|
||||||
|
whereBuffer.append( elementSource.getWhere() );
|
||||||
|
}
|
||||||
|
getCollectionBinding().setManyToManyWhere( whereBuffer.toString() );
|
||||||
|
|
||||||
getCollectionBinding().setManyToManyOrdering( elementSource.getOrder() );
|
getCollectionBinding().setManyToManyOrdering( elementSource.getOrder() );
|
||||||
|
|
||||||
if ( !CollectionHelper.isEmpty( elementSource.getFilterSources() )
|
if ( !CollectionHelper.isEmpty( elementSource.getFilterSources() )
|
||||||
|
@ -514,12 +514,20 @@ public void testClassWhereManyToMany() throws Exception {
|
|||||||
assertTrue( s.createCriteria(Part.class).list().size()==1 ); //there is a where condition on Part mapping
|
assertTrue( s.createCriteria(Part.class).list().size()==1 ); //there is a where condition on Part mapping
|
||||||
assertTrue( s.createCriteria(Part.class).add( Restrictions.eq( "id", p1.getId() ) ).list().size()==1 );
|
assertTrue( s.createCriteria(Part.class).add( Restrictions.eq( "id", p1.getId() ) ).list().size()==1 );
|
||||||
assertTrue( s.createQuery("from Part").list().size()==1 );
|
assertTrue( s.createQuery("from Part").list().size()==1 );
|
||||||
assertTrue( s.createQuery("from Baz baz join baz.moreParts").list().size()==2 );
|
// only Part entities that satisfy the where condition on Part mapping should be included in the collection
|
||||||
|
assertTrue( s.createQuery("from Baz baz join baz.moreParts").list().size()==1 );
|
||||||
baz = (Baz) s.createCriteria(Baz.class).uniqueResult();
|
baz = (Baz) s.createCriteria(Baz.class).uniqueResult();
|
||||||
assertTrue( s.createFilter( baz.getMoreParts(), "" ).list().size()==2 );
|
// only Part entities that satisfy the where condition on Part mapping should be included in the collection
|
||||||
|
assertTrue( s.createFilter( baz.getMoreParts(), "" ).list().size()==1 );
|
||||||
//assertTrue( baz.getParts().size()==1 );
|
//assertTrue( baz.getParts().size()==1 );
|
||||||
s.delete( s.get( Part.class, p1.getId() ));
|
s.delete( s.get( Part.class, p1.getId() ));
|
||||||
s.delete( s.get( Part.class, p2.getId() ));
|
// p2.description does not satisfy the condition on Part mapping, so it's not possible to retrieve it
|
||||||
|
// using Session#get; instead just delete using a native query
|
||||||
|
s.createNativeQuery( "delete from baz_moreParts where baz = :baz AND part = :part" )
|
||||||
|
.setParameter( "baz", baz.getCode() )
|
||||||
|
.setParameter( "part", p2.getId() )
|
||||||
|
.executeUpdate();
|
||||||
|
s.createNativeQuery( "delete from Part where id = :id" ).setParameter( "id", p2.getId() ).executeUpdate();
|
||||||
s.delete(baz);
|
s.delete(baz);
|
||||||
t.commit();
|
t.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user