Search in sources :

Example 1 with CascadeType

use of org.hibernate.annotations.CascadeType in project hibernate-orm by hibernate.

the class AnnotationBinder method getCascadeStrategy.

private static String getCascadeStrategy(javax.persistence.CascadeType[] ejbCascades, Cascade hibernateCascadeAnnotation, boolean orphanRemoval, boolean forcePersist) {
    EnumSet<CascadeType> hibernateCascadeSet = convertToHibernateCascadeType(ejbCascades);
    CascadeType[] hibernateCascades = hibernateCascadeAnnotation == null ? null : hibernateCascadeAnnotation.value();
    if (hibernateCascades != null && hibernateCascades.length > 0) {
        hibernateCascadeSet.addAll(Arrays.asList(hibernateCascades));
    }
    if (orphanRemoval) {
        hibernateCascadeSet.add(CascadeType.DELETE_ORPHAN);
        hibernateCascadeSet.add(CascadeType.REMOVE);
    }
    if (forcePersist) {
        hibernateCascadeSet.add(CascadeType.PERSIST);
    }
    StringBuilder cascade = new StringBuilder();
    for (CascadeType aHibernateCascadeSet : hibernateCascadeSet) {
        switch(aHibernateCascadeSet) {
            case ALL:
                cascade.append(",").append("all");
                break;
            case SAVE_UPDATE:
                cascade.append(",").append("save-update");
                break;
            case PERSIST:
                cascade.append(",").append("persist");
                break;
            case MERGE:
                cascade.append(",").append("merge");
                break;
            case LOCK:
                cascade.append(",").append("lock");
                break;
            case REFRESH:
                cascade.append(",").append("refresh");
                break;
            case REPLICATE:
                cascade.append(",").append("replicate");
                break;
            case EVICT:
            case DETACH:
                cascade.append(",").append("evict");
                break;
            case DELETE:
                cascade.append(",").append("delete");
                break;
            case DELETE_ORPHAN:
                cascade.append(",").append("delete-orphan");
                break;
            case REMOVE:
                cascade.append(",").append("delete");
                break;
        }
    }
    return cascade.length() > 0 ? cascade.substring(1) : "none";
}
Also used : CascadeType(org.hibernate.annotations.CascadeType)

Aggregations

CascadeType (org.hibernate.annotations.CascadeType)1