Domanda

Sospensione classe di persistenza:     @Entità     public class A {

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

    @Basic
    private boolean DELETED;

}

Classe B hanno anche una proprietà CANCELLATO. Come possiamo elaborare proprietà eliminati durante unirsi automaticamente, per selezionare le entità non solo eliminati. Può essere con l'aiuto di alcune annotazioni. E 'possibile?

È stato utile?

Soluzione 2

Molti thx! che è la mia decisione:

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

e HQL "selezionare a.DELETED da A un join a.bSet bSet" sarà genererà SQL nativo in questo modo:

selezionare a0_.DELETED come col_0_0_ da A a0_ inner join B bset1_ su a0_.id = bset1_.a_id e (bset1_.DELETED = 0 o bset1_.DELETED è nullo)

e entityManager.find (...) lavorerà a destra:)

Altri suggerimenti

Hibernate documentazione si dovrebbe usare ResultTransformer (ALIAS_TO_ENTITY_MAP).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top