#set( $foreignClass = ${reference.getReferenceClass()} )
#set( $refPropName = ${reference.getPropertyNameInLocal()} )
#set( $refPropNameCapitalized = ${stringUtils.capitalize( $refPropName )} )
	private ${foreignClass.getName()} $refPropName = null;

	/**
#if( ${reference.size()} == 1 )
#set( $localColumn = ${reference.getEntry(0).getLocal().getOriginal()} )
	 * @hibernate.many-to-one column="${localColumn.getName()}"
#end
	 */
	public ${foreignClass.getName()} get${refPropNameCapitalized}() {
		return this.$refPropName;
	}
	
	public void set${refPropNameCapitalized}(${foreignClass.getName()} $refPropName) {
		this.$refPropName = $refPropName;
#foreach( $entry in ${reference.iterator()} )		
		this.${entry.getLocal().getName()} = ($refPropName == null) ? ${entry.getLocal().getDefaultValue4Velocity()} :
	#set( $foreignPropName = ${stringUtils.capitalize( $entry.getForeign().getName() )} )
	#if( ${entry.getLocal().getType().isPrimitive()} )
    	#if( ${entry.getForeign().getType().isPrimitive()} )
			${refPropName}.get${foreignPropName}();
    	#else
			${refPropName}.get${foreignPropName}().${entry.getLocal().getType().getName()}Value();
    	#end
	#else
    	#if( ${entry.getForeign().getType().isPrimitive()} )
			new ${entry.getLocal().getType().getName()}( ${refPropName}.get${foreignPropName}() );
    	#else
			${refPropName}.get${foreignPropName}();
    	#end
	#end
#end
#*
		if (${refPropName} != null) {
            if (this instanceof ${entity.getName()}) {
				if (!${refPropName}.contains${stringUtils.capitalize($reference.getPropertyNameInReferred(false))}((${entity.getName()}) this)) 
                    ${refPropName}
                            .add${stringUtils.capitalize($reference.getPropertyNameInReferred(false))}((${entity.getName()}) this);
            }
        } else if (old != null) {
            if (this instanceof ${entity.getName()}) {
				if (old.contains${stringUtils.capitalize($reference.getPropertyNameInReferred(false))}((${entity.getName()}) this)) 
                    old.remove${stringUtils.capitalize($reference.getPropertyNameInReferred(false))}((${entity.getName()}) this);
            }
        }
*#
	}
	
	public Serializable get${refPropNameCapitalized}Key(){
#if( ${reference.size()} == 1 )
	#set( $entry = ${reference.getEntry(0)} )
	#set( $entryLocal = ${entry.getLocal()} )
	#if( ${entry.getLocal().getType().isPrimitive()} )
		return (this.get${entryLocal.getCapitalizedName()}() == ${entryLocal.getDefaultValue()}) ? null : new ${entryLocal.getType().toClass().name}(this.get${entryLocal.getCapitalizedName()}());
	#else
		return this.get${entryLocal.getCapitalizedName()}();
	#end
#else
		return this;
#end
	}

	public String get${refPropNameCapitalized}Caption(){
		return (this.get${refPropNameCapitalized}() == null) ? "" : get${refPropNameCapitalized}().getCaption();
	}
	
	public void set${refPropNameCapitalized}Caption(String value){
		//do nothing
	}
