Pregunta

Hibernate persistencia de clase:     @Entidad     public class A {

    @OneToMany(mappedBy = "a")
    private Set<B> bSet = new HashSet<B>();

    @Basic
    private boolean DELETED;

}

Clase B también tiene una propiedad eliminado. ¿Cómo podemos procesar propiedad eliminan durante unirse de forma automática, para las entidades que no sólo se seleccione eliminados. Puede ser con ayuda de algunas anotaciones. Es posible?

¿Fue útil?

Solución 2

Muchos thx! esto es mi resolución:

@Entity
public class A extends DeletableEntity{

    @OneToMany(mappedBy = "a")
    @Where(clause = "DELETED=0 or DELETED is null")
    private Set<B> bSet = new HashSet<B>();

    public Set<B> getBSet() {
        return bSet;
    }

    public void setBSet(Set<B> bSet) {
        this.bSet = bSet;
    }
}

y HQL "seleccione a.DELETED de la A a unirse a a.bSet BSET" será generar SQL nativo de esta manera:

seleccione a0_.DELETED como col_0_0_ de A a0_ combinación interna bset1_ B en a0_.id = bset1_.a_id y (bset1_.DELETED = 0 o bset1_.DELETED es null)

y EntityManager.find (...) estará trabajando derecha:)

Otros consejos

De acuerdo con Hibernate documentación debería utilizar ResultTransformer (ALIAS_TO_ENTITY_MAP).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top