I'm thinking of something similar to the @Where clause, but using property names instead of SQL or HQL.
Use case:
Code:
@Entity (AccessType.FIELD)
public class Disk
{
@Id
protected Long id ;
// current solution, mapping using @Where
@OneToMany (mappedBy = "disk")
@OrderBy ("listOrder")
@Where (clause = "parent_id is null")
protected List<Directory> directory ;
// proposed alternate mapping using @Criterion
@OneToMany (mappedBy = "disk")
@OrderBy ("listOrder")
@Criterion (isNull = "parent")
protected List<Directory> directory ;
}
@Entity (AccessType.FIELD)
{
@Id
protected Long id ;
protected Integer listOrder ;
protected String name ;
@ManyToOne (fetch = FetchType.LAZY)
protected Disk disk ;
@ManyToOne (fetch = FetchType.LAZY)
protected Directory parent ;
@OneToMany (mappedBy = "parent")
@OrderBy ("listOrder")
protected List<Directory> children ;
}
Where "Disk" has a list of root directories (parentless directories). The idea is to not be reliant on the physical mapping of the "parent_id" column using the @Where clause.