Example usage for org.hibernate.criterion CriteriaQuery getEntityName

List of usage examples for org.hibernate.criterion CriteriaQuery getEntityName

Introduction

In this page you can find the example usage for org.hibernate.criterion CriteriaQuery getEntityName.

Prototype

public String getEntityName(Criteria criteria);

Source Link

Document

Get the entity name of an entity

Usage

From source file:corner.orm.hibernate.expression.NewExpressionExample.java

License:Apache License

public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {

    EntityPersister meta = criteriaQuery.getFactory().getEntityPersister(criteriaQuery.getEntityName(criteria));
    String[] propertyNames = meta.getPropertyNames();
    Type[] propertyTypes = meta.getPropertyTypes();
    //TODO: get all properties, not just the fetched ones!
    Object[] values = meta.getPropertyValues(entity, getEntityMode(criteria, criteriaQuery));
    List<TypedValue> list = new ArrayList<TypedValue>();
    for (int i = 0; i < propertyNames.length; i++) {
        Object value = values[i];
        Type type = propertyTypes[i];
        String name = propertyNames[i];

        boolean isPropertyIncluded = i != meta.getVersionProperty() && isPropertyIncluded(value, name, type);

        if (isPropertyIncluded) {
            if (propertyTypes[i].isComponentType()) {
                addComponentTypedValues(name, value, (AbstractComponentType) type, list, criteria,
                        criteriaQuery);//from  w  w  w  .  ja  v  a2  s  .  c o  m
            } else {
                addPropertyTypedValue(name, value, type, list);
            }
        }
    }
    return (TypedValue[]) list.toArray(TYPED_VALUES);
}

From source file:corner.orm.hibernate.expression.NewExpressionExample.java

License:Apache License

private EntityMode getEntityMode(Criteria criteria, CriteriaQuery criteriaQuery) {
    EntityPersister meta = criteriaQuery.getFactory().getEntityPersister(criteriaQuery.getEntityName(criteria));
    EntityMode result = meta.guessEntityMode(entity);
    if (result == null) {
        throw new ClassCastException(entity.getClass().getName());
    }/*from  ww  w  . j  a va  2 s . com*/
    return result;
}