Sleep mode: @wherejointable to filter subtable

I already use the @where clause to filter soft deleted lines for an object. (with the "removed" flag). It works very well.

Now I need to filter the linked table, which stores the history of the linked item. The story strategy is simply to use the max id row of the linked table. This is what I have now:

@Where(clause="deleted = 0" ) EntityA{ @Column(name = "id") Integer id; @Column(name = "deleted") Integer deleted; @OneToMany(mappedBy = "a") List<EntityB> subEntities; EntityB getCurrentEntityB(){ .. loop in java that return the B with the max(id). } } EntityB{ @Column(name = "id") Integer id; @JoinColumn(name = "A_ID") EntityA a; } 

I think I could simplify this with the @WhereJoinTable annotation, but I lost a little opportunity. I tried something like this:

 @Where(clause="deleted = 0" ) EntityA{ ... @OneToOne(mappedBy = "a") @WhereJoinTable(clause = "id in( select max(id) from entityB where a_id = :id )") EntityB currentEntityB; } 

but the syntax is wrong and I really don't know how to do this ...

It’s not easy to find extensive documents about this feature on the Internet ...

Any help?

J.

+4
source share

All Articles