How do I check that an entity is unreferenced in JPA?

Posted by Martin on Stack Overflow See other posts from Stack Overflow or by Martin
Published on 2010-06-10T11:39:11Z Indexed on 2010/06/10 14:22 UTC
Read the original article Hit count: 166

Filed under:
|

I have the following model

@Entity
class Element {
    @Id
    int id;

    @Version
    int version;

    @ManyToOne
    Type type;
}

@Entity
class Type {
    @Id
    int id;

    @Version
    int version;

    @OneToMany(mappedBy="type")
    Collection<Element> elements;

    @Basic(optional=false)
    boolean disabled;
}

and would like to allow Type.disabled = true only if Type.elements is empty. Is there a way to do it atomically?

I would like to prevent an insertion of an Element in a transaction while the corresponding Type is being disabled by an other transaction.

© Stack Overflow or respective owner

Related posts about java

Related posts about jpa