List of usage examples for org.hibernate Session byNaturalId
<T> NaturalIdLoadAccess<T> byNaturalId(Class<T> entityClass);
From source file:org.apereo.portal.jpa.BaseJpaDao.java
License:Apache License
/** * Utility for creating queries based on naturalId. The caller MUST be annotated with {@link * org.apereo.portal.jpa.OpenEntityManager} or {@link Transactional} so that the Hibernate * specific extensions are available./*from w w w .ja v a 2 s . c om*/ */ protected final <T> NaturalIdQuery<T> createNaturalIdQuery(Class<T> entityType) { final EntityManager entityManager = this.getEntityManager(); final Session session; try { session = entityManager.unwrap(Session.class); } catch (IllegalStateException e) { throw new IllegalStateException( "The DAO Method that calls createNaturalIdQuery must be annotated with @OpenEntityManager or @Transactional", e); } final NaturalIdLoadAccess naturalIdLoadAccess = session.byNaturalId(entityType); return new NaturalIdQuery<T>(entityType, naturalIdLoadAccess); }
From source file:org.jasig.jpa.BaseJpaDao.java
License:Apache License
/** * Utility for creating queries based on naturalId. The caller MUST be annotated with {@link OpenEntityManager} or * {@link Transactional} so that the Hibernate specific extensions are available. *//*from w w w . j a v a 2 s . c om*/ protected final <T> NaturalIdQuery<T> createNaturalIdQuery(Class<T> entityType) { final Session session; try { session = entityManager.unwrap(Session.class); } catch (IllegalStateException e) { throw new IllegalStateException( "The DAO Method that calls createNaturalIdQuery must be annotated with @OpenEntityManager or @Transactional", e); } final NaturalIdLoadAccess naturalIdLoadAccess = session.byNaturalId(entityType); return new NaturalIdQuery<T>(entityType, naturalIdLoadAccess); }
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 ww w .j av a 2s .c om projectId = project.getId(); return project; } else { HProject project = (HProject) session.byId(HProject.class).load(projectId); validateProjectState(project); return project; } }
From source file:org.zanata.action.VersionGroupHome.java
License:Open Source License
@Override protected HIterationGroup loadInstance() { Session session = (Session) getEntityManager().getDelegate(); return (HIterationGroup) session.byNaturalId(HIterationGroup.class).using("slug", getSlug()).load(); }
From source file:org.zanata.action.VersionHome.java
License:Open Source License
@Override protected HProjectIteration loadInstance() { Session session = (Session) getEntityManager().getDelegate(); HProject project = (HProject) session.byNaturalId(HProject.class).using("slug", getProjectSlug()).load(); validateProjectState(project);// w ww. j a v a 2 s .c o m if (versionId == null) { HProjectIteration iteration = (HProjectIteration) session.byNaturalId(HProjectIteration.class) .using("slug", getSlug()).using("project", projectDAO.getBySlug(getProjectSlug())).load(); validateIterationState(iteration); versionId = iteration.getId(); return iteration; } else { HProjectIteration iteration = (HProjectIteration) session.load(HProjectIteration.class, versionId); validateIterationState(iteration); return iteration; } }