Example usage for org.hibernate.cfg AccessType getAccessStrategy

List of usage examples for org.hibernate.cfg AccessType getAccessStrategy

Introduction

In this page you can find the example usage for org.hibernate.cfg AccessType getAccessStrategy.

Prototype

public static AccessType getAccessStrategy(javax.persistence.AccessType type) 

Source Link

Document

Convert the JPA access type enum to the corresponding AccessType enum value.

Usage

From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

/**
 * Binds a property to Hibernate runtime meta model. Deals with cascade strategy based on the Grails domain model
 *
 * @param grailsProperty The grails property instance
 * @param prop           The Hibernate property
 * @param mappings       The Hibernate mappings
 *//*from w  ww. ja v  a  2  s .co  m*/
protected void bindProperty(PersistentProperty grailsProperty, Property prop,
        InFlightMetadataCollector mappings) {
    // set the property name
    prop.setName(grailsProperty.getName());
    if (isBidirectionalManyToOneWithListMapping(grailsProperty, prop)) {
        prop.setInsertable(false);
        prop.setUpdateable(false);
    } else {
        prop.setInsertable(getInsertableness(grailsProperty));
        prop.setUpdateable(getUpdateableness(grailsProperty));
    }

    AccessType accessType = AccessType
            .getAccessStrategy(grailsProperty.getMapping().getMappedForm().getAccessType());
    prop.setPropertyAccessorName(accessType.getType());
    prop.setOptional(grailsProperty.isNullable());

    setCascadeBehaviour(grailsProperty, prop);

    // lazy to true
    final boolean isToOne = grailsProperty instanceof ToOne;
    PersistentEntity propertyOwner = grailsProperty.getOwner();
    boolean isLazyable = isToOne
            || !(grailsProperty instanceof Association) && !grailsProperty.equals(propertyOwner.getIdentity());

    if (isLazyable) {
        final boolean isLazy = getLaziness(grailsProperty);
        prop.setLazy(isLazy);

        if (isLazy && isToOne
                && !(PersistentAttributeInterceptable.class.isAssignableFrom(propertyOwner.getJavaClass()))) {
            handleLazyProxy(propertyOwner, grailsProperty);
        }
    }
}