Example usage for org.hibernate.mapping OneToOne setForeignKeyType

List of usage examples for org.hibernate.mapping OneToOne setForeignKeyType

Introduction

In this page you can find the example usage for org.hibernate.mapping OneToOne setForeignKeyType.

Prototype

public void setForeignKeyType(ForeignKeyDirection foreignKeyType) 

Source Link

Document

Sets the foreignKeyType.

Usage

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

protected void bindOneToOne(final GrailsDomainClassProperty property, OneToOne oneToOne, String path,
        String sessionFactoryBeanName) {
    PropertyConfig config = getPropertyConfig(property);
    final GrailsDomainClassProperty otherSide = property.getOtherSide();

    oneToOne.setConstrained(otherSide.isHasOne());
    oneToOne.setForeignKeyType(oneToOne.isConstrained() ? ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT
            : ForeignKeyDirection.FOREIGN_KEY_TO_PARENT);
    oneToOne.setAlternateUniqueKey(true);

    if (config != null && config.getFetch() != null) {
        oneToOne.setFetchMode(config.getFetch());
    } else {/*from ww  w.j av a 2 s  .  c  o  m*/
        oneToOne.setFetchMode(FetchMode.DEFAULT);
    }

    oneToOne.setReferencedEntityName(otherSide.getDomainClass().getFullName());
    oneToOne.setPropertyName(property.getName());

    bindOneToOneInternal(property, oneToOne, path);

    if (otherSide.isHasOne()) {
        PropertyConfig pc = getPropertyConfig(property);
        bindSimpleValue(property, oneToOne, path, pc, sessionFactoryBeanName);
    } else {
        oneToOne.setReferencedPropertyName(otherSide.getName());
    }
}

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

License:Apache License

private static void bindOneToOne(final GrailsDomainClassProperty property, OneToOne oneToOne, String path,
        String sessionFactoryBeanName) {
    PropertyConfig config = getPropertyConfig(property);
    final GrailsDomainClassProperty otherSide = property.getOtherSide();

    oneToOne.setConstrained(otherSide.isHasOne());
    oneToOne.setForeignKeyType(oneToOne.isConstrained() ? ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT
            : ForeignKeyDirection.FOREIGN_KEY_TO_PARENT);
    oneToOne.setAlternateUniqueKey(true);

    if (config != null && config.getFetch() != null) {
        oneToOne.setFetchMode(config.getFetch());
    } else {//from  w  ww. jav  a2  s  . c  o m
        oneToOne.setFetchMode(FetchMode.DEFAULT);
    }

    oneToOne.setReferencedEntityName(otherSide.getDomainClass().getFullName());
    oneToOne.setPropertyName(property.getName());

    if (otherSide.isHasOne()) {
        PropertyConfig pc = getPropertyConfig(property);
        bindSimpleValue(property, oneToOne, path, pc, sessionFactoryBeanName);
    } else {
        oneToOne.setReferencedPropertyName(otherSide.getName());
    }
}

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

License:Apache License

protected void bindOneToOne(final org.grails.datastore.mapping.model.types.OneToOne property, OneToOne oneToOne,
        String path, String sessionFactoryBeanName) {
    PropertyConfig config = getPropertyConfig(property);
    final Association otherSide = property.getInverseSide();

    final boolean hasOne = isHasOne(otherSide);
    oneToOne.setConstrained(hasOne);/*  www . j av a2s.  c o  m*/
    oneToOne.setForeignKeyType(oneToOne.isConstrained() ? ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT
            : ForeignKeyDirection.FOREIGN_KEY_TO_PARENT);
    oneToOne.setAlternateUniqueKey(true);

    if (config != null && config.getFetchMode() != null) {
        oneToOne.setFetchMode(config.getFetchMode());
    } else {
        oneToOne.setFetchMode(FetchMode.DEFAULT);
    }

    oneToOne.setReferencedEntityName(otherSide.getOwner().getName());
    oneToOne.setPropertyName(property.getName());

    bindOneToOneInternal(property, oneToOne, path);

    if (hasOne) {
        PropertyConfig pc = getPropertyConfig(property);
        bindSimpleValue(property, oneToOne, path, pc, sessionFactoryBeanName);
    } else {
        oneToOne.setReferencedPropertyName(otherSide.getName());
    }
}

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

License:Apache License

protected void bindOneToOne(final org.grails.datastore.mapping.model.types.OneToOne property, OneToOne oneToOne,
        String path, String sessionFactoryBeanName) {
    PropertyConfig config = getPropertyConfig(property);
    final Association otherSide = property.getInverseSide();

    final boolean hasOne = isHasOne(otherSide);
    oneToOne.setConstrained(hasOne);/*from   www  .jav a2s  .com*/
    oneToOne.setForeignKeyType(
            oneToOne.isConstrained() ? ForeignKeyDirection.FROM_PARENT : ForeignKeyDirection.TO_PARENT);
    oneToOne.setAlternateUniqueKey(true);

    if (config != null && config.getFetchMode() != null) {
        oneToOne.setFetchMode(config.getFetchMode());
    } else {
        oneToOne.setFetchMode(FetchMode.DEFAULT);
    }

    oneToOne.setReferencedEntityName(otherSide.getOwner().getName());
    oneToOne.setPropertyName(property.getName());
    oneToOne.setReferenceToPrimaryKey(false);

    bindOneToOneInternal(property, oneToOne, path);

    if (hasOne) {
        PropertyConfig pc = getPropertyConfig(property);
        bindSimpleValue(property, oneToOne, path, pc, sessionFactoryBeanName);
    } else {
        oneToOne.setReferencedPropertyName(otherSide.getName());
    }
}