Example usage for org.hibernate Criteria createAlias

List of usage examples for org.hibernate Criteria createAlias

Introduction

In this page you can find the example usage for org.hibernate Criteria createAlias.

Prototype

@Deprecated
public Criteria createAlias(String associationPath, String alias, int joinType, Criterion withClause)
        throws HibernateException;

Source Link

Document

Join an association using the specified join-type, assigning an alias to the joined association.

Usage

From source file:com.devnexus.ting.repository.jpa.PresentationRepositoryImpl.java

License:Apache License

@Override
public List<Presentation> findPresentations(PresentationSearchQuery presentationSearchQuery) {

    Session session = (Session) entityManager.getDelegate();

    final Criteria rootCriteria = session.createCriteria(Presentation.class);
    final Criteria eventCriteria = rootCriteria.createCriteria("event");

    if (presentationSearchQuery.getEvent() != null
            && presentationSearchQuery.getEvent().getEventKey() != null) {
        eventCriteria.add(/*from w  w  w  .  jav a 2s.  c om*/
                Restrictions.eq("eventKey", presentationSearchQuery.getEvent().getEventKey()).ignoreCase());
    }

    if (presentationSearchQuery.getTrack() != null) {
        if (presentationSearchQuery.getTrack().getId() != null) {
            rootCriteria.createAlias("track", "t", JoinType.INNER_JOIN,
                    Restrictions.eq("t.id", presentationSearchQuery.getTrack().getId()));
        } else if (presentationSearchQuery.getTrack().getName() != null) {
            rootCriteria.createAlias("track", "t", JoinType.INNER_JOIN,
                    Restrictions.eq("t.name", presentationSearchQuery.getTrack().getName()).ignoreCase());
        }
    } else {
        rootCriteria.createAlias("track", "t", JoinType.RIGHT_OUTER_JOIN);
    }

    if (!presentationSearchQuery.getPresentationTags().isEmpty()) {
        final Criteria tagsCriteria = rootCriteria.createCriteria("presentationTags");
        tagsCriteria.add(Restrictions.in("name", presentationSearchQuery.getPresentationTagNames()));
    }

    return rootCriteria.list();
}