views:

96

answers:

2

We have a Hibernate based system with Annotations.

Our entities have a custom property DELETED. We have to select non deleted entities with non deleted sub-entities. How can we can do it?

Little sample for describe the situation:

GenericEntity {
 ...
    @Basic
    @Column(name = DELETED)
    protected Boolean deleted = false;


    @ManyToOne
    @JoinColumn(name = LOCATION, nullable = false)
    protected Location location;  
}

Location extends GenericEntity entity, and also has a DELETED property.

How can we select some not deleted GenericEntities with non deleted Locations?

+2  A: 

This HQL should work

select * from GenericEntity g where g.deleted = false and g.location.deleted = false
Aaron Digulla
A: 

Note by using an alias as Aaron has done (g) you can access the entities properties.

Karl