Example usage for org.hibernate.type EntityType getAssociatedEntityName

List of usage examples for org.hibernate.type EntityType getAssociatedEntityName

Introduction

In this page you can find the example usage for org.hibernate.type EntityType getAssociatedEntityName.

Prototype

@Override
public String getAssociatedEntityName(SessionFactoryImplementor factory) 

Source Link

Document

The name of the associated entity.

Usage

From source file:com.autobizlogic.abl.metadata.hibernate.HibMetaRole.java

License:Open Source License

/**
 * Get the MetaEntity at the other end of this role.
 *///from   w  w  w.  j  a  v  a  2s. c om
@Override
public HibMetaEntity getOtherMetaEntity() {

    if (otherMetaEntity != null)
        return otherMetaEntity;

    SessionFactoryImplementor sfi = (SessionFactoryImplementor) metaEntity.getMetaModel().getSessionFactory();
    EntityPersister thisPers = metaEntity.getPersister();
    Type type = thisPers.getPropertyType(roleName);
    if (type.isCollectionType() && !isCollection)
        throw new RuntimeException("Internal metadata inconsistency: role name " + roleName + " of "
                + metaEntity.getEntityName() + " is and isn't a collection");
    else if (type.isEntityType() && isCollection)
        throw new RuntimeException("Internal metadata inconsistency: role name " + roleName + " of "
                + metaEntity.getEntityName() + " is and isn't an entity");

    String otherEntityName = null;
    if (isCollection) {
        CollectionType ctype = (CollectionType) type;
        otherEntityName = ctype.getAssociatedEntityName(sfi);
    } else {
        EntityType etype = (EntityType) type;
        otherEntityName = etype.getAssociatedEntityName(sfi);
    }

    otherMetaEntity = (HibMetaEntity) metaEntity.getMetaModel().getMetaEntity(otherEntityName);
    if (otherMetaEntity == null)
        throw new RuntimeException("Unable to find entity " + otherEntityName + ", which is the value of role "
                + metaEntity.getEntityName() + "." + roleName);

    return otherMetaEntity;
}

From source file:cz.jirutka.rsql.visitor.hibernate.HibernateCriterionVisitor.java

License:Apache License

private Type getPropertyType(EntityType entityType, String property) {
    String associatedEntityName = entityType.getAssociatedEntityName(getSessionFactory());
    ClassMetadata classMetadata = getSessionFactory().getClassMetadata(associatedEntityName);
    property = propertyResolver.getPropertyName(classMetadata.getMappedClass(), property);
    return getPropertyType(classMetadata, property);
}