1

So I understand how to use the JPA/Hibernate filters for immediate sub properties ( demonstrated here: annotation to filter results of a @OneToMany association ) but what I want to do is use a nested property for excluding a reference. So if C is not active as a reference of B, I do not want B included in the set. Here is an example of code that does not work. It complains about c.Active being unknown in there where column. That is because the sql generated contains c_0.is_active as the reference. Is there a way to do something like this?

@Entity
public class A implements Serializable{
    @Id
    @Column(name = "REF")
    private int ref;

    @OneToMany
    @JoinColumn(name = "A_REF", referencedColumnName = "REF")   
    @Filter(name="test")
    private Set<B> bs;
}

@Entity
@FilterDef(name="test", defaultCondition="c.ACTIVE = 1")
public class B implements Serializable{
    @Id
    @Column(name = "A_REF")
    private int aRef;

    private C cObject;
}


@Entity
public class C implements Serializable{
    @Id
    private int ref;

    @Column(name = "ACTIVE")
    private boolean active;
}
Community
  • 1
  • 1
user3170736
  • 511
  • 5
  • 24

1 Answers1

0

I dont think you can use references to other tables this way.

Try this:

@Entity
@FilterDef(name="test", defaultCondition="aRef = 
              (select b.aRef 
               from B b inner join C c on c.ref = b.cRef 
               where c.ACTIVE = 1)"
public class B implements Serializable{
Maciej Kowalski
  • 25,605
  • 12
  • 54
  • 63