Example usage for javax.persistence CascadeType PERSIST

List of usage examples for javax.persistence CascadeType PERSIST

Introduction

In this page you can find the example usage for javax.persistence CascadeType PERSIST.

Prototype

CascadeType PERSIST

To view the source code for javax.persistence CascadeType PERSIST.

Click Source Link

Document

Cascade persist operation

Usage

From source file:edu.harvard.med.screensaver.model.AttachedFile.java

@ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinColumn(name = "screenId", nullable = true, updatable = false)
@org.hibernate.annotations.ForeignKey(name = "fk_attached_file_to_screen")
@org.hibernate.annotations.LazyToOne(value = org.hibernate.annotations.LazyToOneOption.PROXY)
@ToOne(hasNonconventionalSetterMethod = true /* mutually-exclusive parenting relationships */)
public Screen getScreen() {
    return _screen;
}

From source file:example.app.model.Contact.java

@ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinColumn(name = "address_id")
public Address getAddress() {
    return address;
}

From source file:com.anite.zebra.hivemind.om.state.AbstractZebraTaskInstance.java

/**
 * @return/*from  w  w w  .  j  a va2  s .c o m*/
 */
@ManyToOne(targetEntity = ZebraProcessInstance.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
public IProcessInstance getProcessInstance() {
    return this.processInstance;
}

From source file:com.hmsinc.epicenter.model.surveillance.SurveillanceSet.java

/**
 * @return the attributes/* ww  w.  j  a v  a  2s .  c  om*/
 */
@ManyToMany(cascade = { CascadeType.PERSIST,
        CascadeType.MERGE }, fetch = FetchType.LAZY, targetEntity = Attribute.class)
@JoinTable(name = "SURVEILLANCE_SET_ATTRIB", joinColumns = {
        @JoinColumn(name = "ID_SURVEILLANCE_SET") }, inverseJoinColumns = {
                @JoinColumn(name = "ID_ATTRIBUTE") })
@ForeignKey(name = "FK_SURVEILLANCE_SET_ATTRIB_1", inverseName = "FK_SURVEILLANCE_SET_ATTRIB_2")
public Set<Attribute> getAttributes() {
    return attributes;
}

From source file:edu.harvard.med.screensaver.model.AttachedFile.java

@ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinColumn(name = "screensaverUserId", nullable = true, updatable = false)
@org.hibernate.annotations.ForeignKey(name = "fk_attached_file_to_screening_room_user")
@org.hibernate.annotations.LazyToOne(value = org.hibernate.annotations.LazyToOneOption.PROXY)
@ToOne(hasNonconventionalSetterMethod = true /* mutually-exclusive parenting relationships */)
public ScreeningRoomUser getScreeningRoomUser() {
    return _screeningRoomUser;
}

From source file:com.hmsinc.epicenter.model.workflow.Investigation.java

/**
 * @return the state//www. ja v  a2 s  . c o m
 */
@ManyToOne(cascade = { CascadeType.MERGE, CascadeType.PERSIST }, fetch = FetchType.LAZY)
@JoinColumn(name = "ID_WORKFLOW_STATE", unique = false, nullable = false, insertable = true, updatable = true)
@org.hibernate.annotations.ForeignKey(name = "FK_INVESTIGATION_1")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public WorkflowState getState() {
    return state;
}

From source file:com.impetus.kundera.mongodb.MongoDBDataHandler.java

public BasicDBObject getDocumentFromEntity(EntityManagerImpl em, EntityMetadata m, Object entity)
        throws PropertyAccessException {
    List<Column> columns = m.getColumnsAsList();
    BasicDBObject dbObj = new BasicDBObject();

    //Populate columns
    for (Column column : columns) {
        try {/*from  ww w  . ja v a 2s.  c  o m*/
            extractEntityField(entity, dbObj, column);
        } catch (PropertyAccessException e1) {
            log.error("Can't access property " + column.getField().getName());
        }
    }

    //Populate Relationship fields
    List<Relation> relations = m.getRelations();
    for (Relation relation : relations) {
        // Cascade?
        if (!relation.getCascades().contains(CascadeType.ALL)
                && !relation.getCascades().contains(CascadeType.PERSIST)) {
            continue;
        }

        Class<?> embeddedEntityClass = relation.getTargetEntity(); //Target entity
        Field embeddedEntityField = relation.getProperty(); //Mapped to this property         
        boolean optional = relation.isOptional(); // Is it optional         
        Object embeddedObject = PropertyAccessorHelper.getObject(entity, embeddedEntityField); // Value         

        EntityMetadata relMetadata = em.getMetadataManager().getEntityMetadata(embeddedEntityClass);
        relMetadata.addColumn(relMetadata.getIdColumn().getName(), relMetadata.getIdColumn()); //Add PK column

        if (embeddedObject == null) {
            if (!optional) {
                throw new PersistenceException(
                        "Field " + embeddedEntityField + " is not optional, and hence must be set.");
            }

        } else {
            if (relation.isUnary()) {
                BasicDBObject relDBObj = getDocumentFromEntity(em, relMetadata, embeddedObject);
                dbObj.put(embeddedEntityField.getName(), relDBObj);

            } else if (relation.isCollection()) {
                Collection collection = (Collection) embeddedObject;
                BasicDBObject[] relDBObjects = new BasicDBObject[collection.size()];
                int count = 0;
                for (Object o : collection) {
                    relDBObjects[count] = getDocumentFromEntity(em, relMetadata, o);
                    count++;
                }
                dbObj.put(embeddedEntityField.getName(), relDBObjects);
            }

        }

    }
    return dbObj;
}

From source file:example.app.model.Contact.java

@ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinColumn(name = "phone_number_id")
public PhoneNumber getPhoneNumber() {
    return phoneNumber;
}

From source file:com.hmsinc.epicenter.model.surveillance.SurveillanceTask.java

/**
 * @return the sets/*from  www .  j ava2  s.  co m*/
 */
@ManyToMany(cascade = { CascadeType.PERSIST,
        CascadeType.MERGE }, fetch = FetchType.LAZY, targetEntity = SurveillanceSet.class)
@JoinTable(name = "SURVEILLANCE_TASK_SET", joinColumns = {
        @JoinColumn(name = "ID_SURVEILLANCE_TASK") }, inverseJoinColumns = {
                @JoinColumn(name = "ID_SURVEILLANCE_SET") })
@ForeignKey(name = "FK_SURVEILLANCE_TASK_SET_1", inverseName = "FK_SURVEILLANCE_TASK_SET_2")
public Set<SurveillanceSet> getSets() {
    return sets;
}

From source file:com.hmsinc.epicenter.model.workflow.Investigation.java

/**
 * @return the assignedTo/*from w w  w  . j  a v a  2 s . c  o m*/
 */
@ManyToOne(cascade = { CascadeType.MERGE, CascadeType.PERSIST }, fetch = FetchType.LAZY)
@JoinColumn(name = "ID_APP_USER_ASSIGNED_TO", unique = false, nullable = true, insertable = true, updatable = true)
@org.hibernate.annotations.ForeignKey(name = "FK_INVESTIGATION_2")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public EpiCenterUser getAssignedTo() {
    return assignedTo;
}