Example usage for org.hibernate Session byId

List of usage examples for org.hibernate Session byId

Introduction

In this page you can find the example usage for org.hibernate Session byId.

Prototype

<T> IdentifierLoadAccess<T> byId(Class<T> entityClass);

Source Link

Document

Create an IdentifierLoadAccess instance to retrieve the specified entity by primary key.

Usage

From source file:org.zanata.action.ProjectHome.java

License:Open Source License

@Override
protected HProject loadInstance() {
    Session session = (Session) getEntityManager().getDelegate();
    if (projectId == null) {
        HProject project = (HProject) session.byNaturalId(HProject.class).using("slug", getSlug()).load();
        validateProjectState(project);/*from   w w w  .  j a v  a2s  .com*/
        projectId = project.getId();
        return project;
    } else {
        HProject project = (HProject) session.byId(HProject.class).load(projectId);
        validateProjectState(project);
        return project;
    }
}

From source file:vn.vnpttech.ssdc.nms.xmpp.connector.dao.XmppGenericDaoImpl.java

License:Apache License

@Override
public T get(PK id) {
    Session session = getSession();
    Transaction tx = null;//ww  w . j a v a  2 s. c o  m
    try {
        IdentifierLoadAccess byId = session.byId(persistentClass);
        T entity = (T) byId.load(id);
        return entity;
    } catch (Exception e) {
        if (tx != null) {
            tx.rollback();
        }
        e.printStackTrace();
        return null;
    } finally {
        session.close();
    }
}