-->
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.  [ 1 post ] 
Author Message
 Post subject: Filter on class hierarchy broken since 4.1.5.SP1 (HHH-2394)?
PostPosted: Tue Jun 24, 2014 5:21 am 
Newbie

Joined: Mon Dec 27, 2010 7:02 am
Posts: 2
I'm trying to migrate a project from 3.5.6-Final to 4.3.5.Final and am running into a problem wrt Filters and subclasses.

We have a simple class hierarchy that has a @Filter annotation on the parent class, as such:

Code:
@MappedSuperclass
@FilterDef(name = FILTER_SOFT_DELETES, defaultCondition = "deleted = 0", parameters = {})
@Filter(name = FILTER_SOFT_DELETES)
public class AuditableEntity {

    @Column(name = "deleted", nullable = false, columnDefinition = "numeric(1,0) default 0")
    private boolean deleted = false;
}

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "legal_entity")
public class LegalEntity extends AuditableEntity {
}

@Entity
@Table(name = "person")
public class Person extends LegalEntity {
}


Now when enabling the filter, a where clause gets generated that checks for delete=0 on both the legal_entity and person table!
This is obviously wrong and the query fails. This was not the case in 3.5.6-Final!

During debugging I noticed a couple of things:
  • Person has a filter defined in its SubClass representation, while obviously Person.java does not (during initialization, AnnotationBinder adds these parent filters to EntityBinder, which in turns creates PerisistentClass instances, SubClass being one).
  • All filters from its superclasses are collected when invoking
    SubClass.getFilters():
    Code:
       public java.util.List getFilters() {
          java.util.List filters = new ArrayList(super.getFilters());
          filters.addAll(getSuperclass().getFilters());
          return filters;
       }
  • FilterConfiguration.java (the filter instances) have no 'equals' implementation, causing filters with the same name to appear as many times as there are concrete tables in the hierarchy.

The end result is that upon querying for Person, I end up with two identical filters, both being added to the where clause:
Code:
SELECT ... FROM person person0_
       INNER JOIN legal_entity person0_1_
          ON person0_.id = person0_1_.id
WHERE     person0_.deleted = 0
       AND person0_1_.deleted = 0
       AND person0_.id = ?;


Of course, "person0_1_.deleted = 0" yields a syntax error.

I noticed that a lot of changes were made to filters to enable being able to define filters on subclasses in https://hibernate.atlassian.net/browse/HHH-2394, but it seems this got broken along the way?

Any suggestions?

edit: I was able to confirm this is only a true problem when you have @Inheritance(strategy = InheritanceType.JOINED) specified. If you don't , then the deleted = 0 still gets added as many times are you have concrete classes, but now it's all on the same table... I'm going to go ahead and create a bug report for this.

edit2: bug report created: https://hibernate.atlassian.net/browse/HHH-9257


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

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.