Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override hibernate JPA filter on inherited class?

I am using hibernate JPA.

I have a BasePersonnel class as super class that has a filter:

@Entity
@Table(name = "APP_PERSONEL")
@Filters({
    @Filter(name = "authorize", 
            condition = " 1 = 1 ")
})
public class BasePersonel extends BaseEntity<Integer> {
    ...
}

and it has a child class:

@Entity
@Table(name = "RTS_PERSONNEL")
@Filters({
    @Filter(name = "authorize",
            condition = " 2 = 2 ")
})
public class Personnel extends BasePersonel {
    ...
}

When I run query on Personnel class using hql, both filters(ie super class's filter and child class's filter) append to where clause. But I want just child class filter append to where clause.

Is there any solution to override super class filter?

like image 967
Ali Sohrabi Avatar asked Nov 07 '22 00:11

Ali Sohrabi


1 Answers

You can use a @Subselect when mapping the entity.

@Entity
@Subselect("select * from APP_PERSONEL where authorize = 1")
public class BasePersonel extends BaseEntity<Integer> {
    ...
}
like image 86
Vlad Mihalcea Avatar answered Nov 12 '22 14:11

Vlad Mihalcea