views:

624

answers:

2

I have an Entity which has an association to another Entity annotated with @Where, like so

public class EntityA {

    @OneToMany
    @Where(...)
    private List<EntityB> entityBList;

}

Recently the inevitable has happened, I need to load EntityB's that don't conform to the @Where clause. I could remove the @Where annotation, but it is used a lot, so ideally I don't want to do that. Apart from loading the list of EntityB's manually, with another query, what are my options? Can I tell Hibernate to ignore the @Where annotation?

A: 

You can map another property with same data like this:

public class EntityA {

    @OneToMany
    @JoinColumn(name='theColumnName', insertable=false, updateable=false)
    private List<EntityB> entityBListReadOnly;

}

Important to set as updateable false and insertable falso to avoid consistency problems in your data!

Gabriel
+1  A: 

After lots of research it appears that this is simply impossible. I'd strongly suggest avoiding @Where, as it is hard to predict beforehand if you'll ever need those associations or not.

Zecrates