@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 ;
}

Advertisements