public static FetchMode annotationFetchModeToHibernateFetchMode(org.hibernate.annotations.FetchMode annotationFetchMode) { switch ( annotationFetchMode ) { case JOIN: { return FetchMode.JOIN; } case SELECT: { return FetchMode.SELECT; } case SUBSELECT: { // todo - is this correct? can the conversion be made w/o any additional information, eg // todo - association nature return FetchMode.SELECT; } default: { throw new AssertionFailure( "Unknown fetch mode" ); } } }
/** * Determine the appropriate type of join (if any) to use to fetch the * given association. * * @param persister The owner of the association. * @param path The path to the association * @param propertyNumber The property number representing the association. * @param associationType The association type. * @param metadataFetchMode The metadata-defined fetch mode. * @param metadataCascadeStyle The metadata-defined cascade style. * @param lhsTable The owner table * @param lhsColumns The owner join columns * @param nullable Is the association nullable. * @param currentDepth Current join depth * @return type of join to use ({@link org.hibernate.sql.JoinType#INNER_JOIN}, * {@link org.hibernate.sql.JoinType#LEFT_OUTER_JOIN}, or -1 to indicate no joining. * @throws MappingException ?? */ protected JoinType getJoinType( OuterJoinLoadable persister, final PropertyPath path, int propertyNumber, AssociationType associationType, FetchMode metadataFetchMode, CascadeStyle metadataCascadeStyle, String lhsTable, String[] lhsColumns, final boolean nullable, final int currentDepth) throws MappingException { return getJoinType( associationType, metadataFetchMode, path, lhsTable, lhsColumns, nullable, currentDepth, metadataCascadeStyle ); }
/** * Determine the appropriate associationType of join (if any) to use to fetch the * given association. * * @param associationType The association associationType. * @param config The metadata-defined fetch mode. * @param path The path to the association * @param lhsTable The owner table * @param lhsColumns The owner join columns * @param nullable Is the association nullable. * @param currentDepth Current join depth * @param cascadeStyle The metadata-defined cascade style. * @return type of join to use ({@link org.hibernate.sql.JoinType#INNER_JOIN}, * {@link org.hibernate.sql.JoinType#LEFT_OUTER_JOIN}, or -1 to indicate no joining. * @throws MappingException ?? */ protected JoinType getJoinType( AssociationType associationType, FetchMode config, PropertyPath path, String lhsTable, String[] lhsColumns, boolean nullable, int currentDepth, CascadeStyle cascadeStyle) throws MappingException { if ( !isJoinedFetchEnabled( associationType, config, cascadeStyle ) ) { return JoinType.NONE; } if ( isTooDeep(currentDepth) || ( associationType.isCollectionType() && isTooManyCollections() ) ) { return JoinType.NONE; } if ( isDuplicateAssociation( lhsTable, lhsColumns, associationType ) ) { return JoinType.NONE; } return getJoinType( nullable, currentDepth ); }
/** * Does the mapping, and Hibernate default semantics, specify that * this association should be fetched by outer joining */ protected boolean isJoinedFetchEnabledInMapping(FetchMode config, AssociationType type) throws MappingException { if ( !type.isEntityType() && !type.isCollectionType() ) { return false; } else { if (config==FetchMode.JOIN) return true; if (config==FetchMode.SELECT) return false; if ( type.isEntityType() ) { //TODO: look at the owning property and check that it // isn't lazy (by instrumentation) EntityType entityType =(EntityType) type; EntityPersister persister = getFactory().getEntityPersister( entityType.getAssociatedEntityName() ); return !persister.hasProxy(); } else { return false; } } }
@Override protected JoinType getJoinType( AssociationType associationType, FetchMode config, PropertyPath path, String lhsTable, String[] lhsColumns, boolean nullable, int currentDepth, CascadeStyle cascadeStyle) throws MappingException { return getJoinType( null, path, -1, associationType, config, cascadeStyle, lhsTable, lhsColumns, nullable, currentDepth ); }
public BaselineAttributeInformation( boolean lazy, boolean insertable, boolean updateable, ValueGeneration valueGenerationStrategy, boolean nullable, boolean dirtyCheckable, boolean versionable, CascadeStyle cascadeStyle, FetchMode fetchMode) { this.lazy = lazy; this.insertable = insertable; this.updateable = updateable; this.valueGenerationStrategy = valueGenerationStrategy; this.nullable = nullable; this.dirtyCheckable = dirtyCheckable; this.versionable = versionable; this.cascadeStyle = cascadeStyle; this.fetchMode = fetchMode; }
public ComponentType(TypeFactory.TypeScope typeScope, ComponentMetamodel metamodel) { this.typeScope = typeScope; // for now, just "re-flatten" the metamodel since this is temporary stuff anyway (HHH-1907) this.isKey = metamodel.isKey(); this.propertySpan = metamodel.getPropertySpan(); this.propertyNames = new String[ propertySpan ]; this.propertyTypes = new Type[ propertySpan ]; this.propertyNullability = new boolean[ propertySpan ]; this.cascade = new CascadeStyle[ propertySpan ]; this.joinedFetch = new FetchMode[ propertySpan ]; for ( int i = 0; i < propertySpan; i++ ) { StandardProperty prop = metamodel.getProperty( i ); this.propertyNames[i] = prop.getName(); this.propertyTypes[i] = prop.getType(); this.propertyNullability[i] = prop.isNullable(); this.cascade[i] = prop.getCascadeStyle(); this.joinedFetch[i] = prop.getFetchMode(); if (!prop.isNullable()) { hasNotNullProperty = true; } } this.entityMode = metamodel.getEntityMode(); this.componentTuplizer = metamodel.getComponentTuplizer(); }
private static DetachedCriteria createFlowsCriteria(FlowFinderCriteria finderCriteria) { DetachedCriteria criteria = DetachedCriteria.forClass(Flow.class) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .setFetchMode("parts", FetchMode.JOIN) // eager .add(ge("creationTime", finderCriteria.getFrom())) .addOrder(Order.desc("identifier")); if (finderCriteria.getApplication() != null) { // constrain query to a certain application name criteria.add(eq("application", finderCriteria .getApplication())); } if (finderCriteria.getTo() != null) { // there's an upper limit to creationTime property criteria.add(Restrictions .le("creationTime", finderCriteria.getTo())); } return criteria; }
@Test public void getAllIsCacheableAndReturnsDistinctResult() throws Exception { List<Object> expectedResult = new ArrayList<Object>(); when(session.createCriteria(Object.class)).thenReturn(criteria); when(criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)).thenReturn(criteria); when(criteria.setCacheable(true)).thenReturn(criteria); when(criteria.setFetchMode("association", FetchMode.JOIN)).thenReturn(criteria); when(criteria.list()).thenReturn(expectedResult); assertThat(dao.getAll("association")).isSameAs(expectedResult); verify(sessionFactory, atLeastOnce()).getCurrentSession(); verify(criteria).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); verify(criteria).setCacheable(true); verify(criteria).setFetchMode("association", FetchMode.JOIN); }
@Override public void execute() { try{ Transaction tx = session.beginTransaction(); // Query q = session.createQuery("from Users u where u.userId = :userid"); // q.setString("userid", userID); // user = (Users)q.uniqueResult(); Criteria crt = session.createCriteria(Users.class).setFetchMode("signings", FetchMode.JOIN).setFetchMode("lendings", FetchMode.JOIN) .setFetchMode("duplicates", FetchMode.JOIN).setFetchMode("picturebooks", FetchMode.JOIN).setFetchMode("lendings.warningses", FetchMode.JOIN); crt.add( Restrictions.eq("userId", userID)); user = (Users)crt.uniqueResult(); tx.commit(); log.info("loading user: "+ userID); }catch (Exception e){ log.error("loading user failed: " + userID); log.error(e.getMessage()); } }
/** * @param property The property to bind * @param manyToOne The inverse side */ protected void bindUnidirectionalOneToManyInverseValues(ToMany property, ManyToOne manyToOne) { PropertyConfig config = getPropertyConfig(property); if (config == null) { manyToOne.setLazy(true); } else { manyToOne.setIgnoreNotFound(config.getIgnoreNotFound()); final FetchMode fetch = config.getFetchMode(); if(!fetch.equals(FetchMode.JOIN) && !fetch.equals(FetchMode.EAGER)) { manyToOne.setLazy(true); } final Boolean lazy = config.getLazy(); if(lazy != null) { manyToOne.setLazy(lazy); } } // set referenced entity manyToOne.setReferencedEntityName(property.getAssociatedEntity().getName()); }
/** */ protected void bindManyToOneValues(org.grails.datastore.mapping.model.types.Association property, ManyToOne manyToOne) { PropertyConfig config = getPropertyConfig(property); if (config != null && config.getFetchMode() != null) { manyToOne.setFetchMode(config.getFetchMode()); } else { manyToOne.setFetchMode(FetchMode.DEFAULT); } manyToOne.setLazy(getLaziness(property)); if (config != null) { manyToOne.setIgnoreNotFound(config.getIgnoreNotFound()); } // set referenced entity manyToOne.setReferencedEntityName(property.getAssociatedEntity().getName()); }
/** * {@inheritDoc} * * @see com.communote.server.persistence.tasks.TaskDao#findNextScheduledTasks() */ @SuppressWarnings("unchecked") @Override protected Collection<Task> handleFindNextScheduledTasks(Date upperBound, int maxTasks, Collection<Long> taskIdsToExclude) { Criteria criteria = getSession().createCriteria(Task.class); criteria.setFetchMode(TaskConstants.PROPERTIES, FetchMode.JOIN); criteria.add(Restrictions.eq(TaskConstants.TASKSTATUS, TaskStatus.PENDING)); criteria.add(Restrictions.eq(TaskConstants.ACTIVE, true)); criteria.addOrder(Order.asc(TaskConstants.NEXTEXECUTION)); if (taskIdsToExclude != null && taskIdsToExclude.size() > 0) { criteria.add(Restrictions.not(Restrictions.in(TaskConstants.ID, taskIdsToExclude))); } if (upperBound != null) { criteria.add(Restrictions.lt(TaskConstants.NEXTEXECUTION, upperBound)); } criteria.setMaxResults(maxTasks); return criteria.list(); }
/** * An API to fetch all Field types by document type name. * * @param docTypeName String * @param batchInstanceIdentifier String * @param isKVExtraction boolean * @return List<FieldType> */ @Override public List<FieldType> getFdTypeByDocumentTypeName(String docTypeName, String batchInstanceIdentifier, boolean isKVExtraction) { LOG.info("batchInstanceID ID : " + batchInstanceIdentifier); DetachedCriteria criteria = criteria(); criteria.createAlias(DOC_TYPE, DOC_TYPE, JoinFragment.INNER_JOIN); criteria.add(Restrictions.eq(DOC_TYPE_NAME, docTypeName)); criteria.createAlias(DOC_TYPE_BATCH_CLASS, BATCH_CLASS1, JoinFragment.INNER_JOIN); if (isKVExtraction) { criteria.setFetchMode("kvExtraction", FetchMode.JOIN); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); } DetachedCriteria subQuery = criteria(BatchInstance.class); subQuery.add(Restrictions.eq(IDENTIFIER, batchInstanceIdentifier)); subQuery.createAlias(BATCH_CLASS, BATCH_CLASS2, JoinFragment.INNER_JOIN); subQuery.setProjection(Projections.property(BATCH_CLASS2_IDENTIFIER)); criteria.add(Subqueries.propertyEq(BATCH_CLASS1_IDENTIFIER, subQuery)); criteria.addOrder(org.hibernate.criterion.Order.asc(FIELD_ORDER_NUMBER)); return find(criteria); }
/** * An API to fetch all Field types by document type name. * * @param docTypeName String * @param batchInstanceIdentifier String * @return List<FieldType> */ @Override public List<FieldType> getFdTypeAndRegexValidationByDocTypeName(String docTypeName, String batchInstanceIdentifier) { LOG.info("batchInstanceID ID : " + batchInstanceIdentifier); DetachedCriteria criteria = criteria(); criteria.createAlias(DOC_TYPE, DOC_TYPE, JoinFragment.INNER_JOIN); criteria.add(Restrictions.eq(DOC_TYPE_NAME, docTypeName)); criteria.createAlias(DOC_TYPE_BATCH_CLASS, BATCH_CLASS1, JoinFragment.INNER_JOIN); criteria.setFetchMode(REGEX_VALIDATION, FetchMode.JOIN); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); DetachedCriteria subQuery = criteria(BatchInstance.class); subQuery.add(Restrictions.eq(IDENTIFIER, batchInstanceIdentifier)); subQuery.createAlias(BATCH_CLASS, BATCH_CLASS2, JoinFragment.INNER_JOIN); subQuery.setProjection(Projections.property(BATCH_CLASS2_IDENTIFIER)); criteria.add(Subqueries.propertyEq(BATCH_CLASS1_IDENTIFIER, subQuery)); criteria.addOrder(org.hibernate.criterion.Order.asc(FIELD_ORDER_NUMBER)); return find(criteria); }
/** * Get the join type (inner, outer, etc) or -1 if the * association should not be joined. Override on * subclasses. */ protected int getJoinType( AssociationType type, FetchMode config, String path, String lhsTable, String[] lhsColumns, boolean nullable, int currentDepth, CascadeStyle cascadeStyle) throws MappingException { if ( !isJoinedFetchEnabled(type, config, cascadeStyle) ) return -1; if ( isTooDeep(currentDepth) || ( type.isCollectionType() && isTooManyCollections() ) ) return -1; final boolean dupe = isDuplicateAssociation(lhsTable, lhsColumns, type); if (dupe) return -1; return getJoinType(nullable, currentDepth); }
public ComponentType(ComponentMetamodel metamodel) { // for now, just "re-flatten" the metamodel since this is temporary stuff anyway (HHH-1907) this.isKey = metamodel.isKey(); this.propertySpan = metamodel.getPropertySpan(); this.propertyNames = new String[ propertySpan ]; this.propertyTypes = new Type[ propertySpan ]; this.propertyNullability = new boolean[ propertySpan ]; this.cascade = new CascadeStyle[ propertySpan ]; this.joinedFetch = new FetchMode[ propertySpan ]; for ( int i = 0; i < propertySpan; i++ ) { StandardProperty prop = metamodel.getProperty( i ); this.propertyNames[i] = prop.getName(); this.propertyTypes[i] = prop.getType(); this.propertyNullability[i] = prop.isNullable(); this.cascade[i] = prop.getCascadeStyle(); this.joinedFetch[i] = prop.getFetchMode(); } this.tuplizerMapping = metamodel.getTuplizerMapping(); }
public void testNonlazyCollection() throws Exception { Session s = openSession(); Baz baz = new Baz(); s.save(baz); s.flush(); s.connection().commit(); s.close(); s = openSession(); baz = (Baz) s.createCriteria(Baz.class) //.setComment("criteria test") .setFetchMode("stringDateMap", FetchMode.EAGER) .uniqueResult(); assertTrue( Hibernate.isInitialized( baz.getFooToGlarch() ) ); assertTrue( Hibernate.isInitialized( baz.getFooComponentToFoo() ) ); assertTrue( !Hibernate.isInitialized( baz.getStringSet() ) ); assertTrue( Hibernate.isInitialized( baz.getStringDateMap() ) ); s.delete(baz); s.flush(); s.connection().commit(); s.close(); }
public void testWhere() { Session s = openSession(); s.getTransaction().begin(); File parent = new File("parent", null); s.persist( parent ); s.persist( new File("child", parent) ); File deletedChild = new File("deleted child", parent); deletedChild.setDeleted(true); s.persist( deletedChild ); File deletedParent = new File("deleted parent", null); deletedParent.setDeleted(true); s.persist( deletedParent ); s.flush(); s.clear(); parent = (File) s.createCriteria(File.class) .setFetchMode("children", FetchMode.JOIN) .add( Restrictions.isNull("parent") ) .uniqueResult(); assertEquals( parent.getChildren().size(), 1 ); s.clear(); parent = (File) s.createQuery("from File f left join fetch f.children where f.parent is null") .uniqueResult(); assertEquals( parent.getChildren().size(), 1 ); s.getTransaction().commit(); s.close(); }
/** * * @param t * Set a the fetched object * @param fetch * Set the name of the fetch profile */ protected void enableProfilePostQuery(final T t, final String fetch) { if (fetch != null && t != null) { Fetch[] fetchDefs = getProfile(fetch); if(fetchDefs == null || fetchDefs.length < 1) { return; } for (Fetch f : fetchDefs) { if (f.getMode().equals(FetchMode.SELECT)) { String association = f.getAssociation(); if (association.indexOf(".") == -1) { initializeProperty(t, f.getAssociation()); } else { List<String> associations = Arrays.asList(association.split("\\.")); initializeProperties(t, associations); } } } } }
/** * @param t * Set the taxon * @param fetch * Set the fetch profile */ @Override public final void enableProfilePostQuery(final Taxon t, final String fetch) { if (fetch != null && t != null) { for (Fetch f : getProfile(fetch)) { if (f.getMode().equals(FetchMode.SELECT)) { String association = f.getAssociation(); if (association.indexOf(".") == -1) { initializeProperty(t, f.getAssociation()); } else { List<String> associations = Arrays.asList(association .split("\\.")); initializeProperties(t, associations); } } } } }
/** * * @param t * Set a the fetched object * @param fetch * Set the name of the fetch profile */ protected void enableProfilePostQuery(final T t, final String fetch) { if (fetch != null && t != null) { Fetch[] fetchDefs = getProfile(fetch); if(fetchDefs == null || fetchDefs.length < 1) { return; } for (Fetch f : fetchDefs) { if (f.getMode().equals(FetchMode.SELECT)) { String association = f.getAssociation(); logger.debug("Setting fetch mode to SELECT for {}", association); if (association.indexOf(".") == -1) { initializeProperty(t, f.getAssociation()); } else { List<String> associations = Arrays.asList(association.split("\\.")); initializeProperties(t, associations); } } } } }
@Override public final void enableProfilePostQuery(final Taxon t, final String fetch) { if (fetch != null && t != null) { for (Fetch f : getProfile(fetch)) { if (f.getMode().equals(FetchMode.SELECT)) { String association = f.getAssociation(); if (association.indexOf(".") == -1) { initializeProperty(t, f.getAssociation()); } else { List<String> associations = Arrays.asList(association .split("\\.")); initializeProperties(t, associations); } } } } }
/** * {@inheritDoc} */ public WallItemComment getWallItemComment(final long wallItemCommentId) { HibernateCallback<List<WallItemComment>> hcb = session -> session.createCriteria(WallItemComment.class) .add(Restrictions.eq(ID, wallItemCommentId)) .setFetchMode("wallItem", FetchMode.JOIN) .list(); List<WallItemComment> comments = getHibernateTemplate().execute(hcb); if (comments.size() > 0) { return comments.get(0); } else { return null; } }
public Gradebook getGradebookByTitleAndContext(final String title, final String context) { if (title == null || context == null) { throw new IllegalArgumentException("Null Argument"); } else { HibernateCallback hcb = session -> { Criteria crit = session.createCriteria(GradebookImpl.class).add( Expression.eq(TITLE, title)).add(Expression.eq(CONTEXT, context)) .setFetchMode(STUDENTS, FetchMode.EAGER); Gradebook gradebook = (Gradebook) crit.uniqueResult(); return gradebook; }; return (Gradebook) getHibernateTemplate().execute(hcb); } }
public SortedSet getStudentGradesForGradebook(final Gradebook gradebook) throws IllegalArgumentException { if (gradebook == null) { throw new IllegalArgumentException("Null Argument"); } else { HibernateCallback hcb = session -> { // get syllabi in an eager fetch mode Criteria crit = session.createCriteria(Gradebook.class).add( Expression.eq(ID, gradebook.getId())).setFetchMode(STUDENTS, FetchMode.EAGER); Gradebook grades = (Gradebook) crit.uniqueResult(); if (grades != null) { return grades.getStudents(); } return new TreeSet(); }; return (SortedSet) getHibernateTemplate().execute(hcb); } }
/** * getSyllabiForSyllabusItem returns the collection of syllabi * @param syllabusItem */ public Set getSyllabiForSyllabusItem(final SyllabusItem syllabusItem) { if (syllabusItem == null) { throw new IllegalArgumentException("Null Argument"); } else { HibernateCallback<Set> hcb = session -> { // get syllabi in an eager fetch mode Criteria crit = session.createCriteria(SyllabusItemImpl.class) .add(Expression.eq(SURROGATE_KEY, syllabusItem.getSurrogateKey())) .setFetchMode(SYLLABI, FetchMode.EAGER); SyllabusItem syllabusItem1 = (SyllabusItem) crit.uniqueResult(); if (syllabusItem1 != null){ return syllabusItem1.getSyllabi(); } return new TreeSet(); }; return getHibernateTemplate().execute(hcb); } }
public Set getSyllabusAttachmentsForSyllabusData(final SyllabusData syllabusData) { if (syllabusData == null) { throw new IllegalArgumentException("Null Argument"); } else { HibernateCallback<Set<SyllabusAttachment>> hcb = session -> { Criteria crit = session.createCriteria(SyllabusDataImpl.class) .add(Expression.eq(SYLLABUS_DATA_ID, syllabusData.getSyllabusId())) .setFetchMode(ATTACHMENTS, FetchMode.EAGER); SyllabusData syllabusData1 = (SyllabusData) crit.uniqueResult(); if (syllabusData1 != null){ return syllabusData1.getAttachments(); } return new TreeSet(); }; return getHibernateTemplate().execute(hcb); } }
/** * Find all the groups that need to be end dated. * @return A List of groups to be end dated. */ @SuppressWarnings("unchecked") public List<TargetGroup> findEndedGroups() { return getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session aSession) throws HibernateException, SQLException { List<TargetGroup> results = aSession.createCriteria(TargetGroup.class) .add(Restrictions.ne("state", TargetGroup.STATE_ACTIVE)) .add(Restrictions.lt("toDate", new Date())) .setFetchMode("schedules", FetchMode.JOIN) .setFetchMode("parents", FetchMode.JOIN) .setFetchMode("children", FetchMode.JOIN) .list(); log.debug("Found " + results.size() + " groups that need to be unscheduled"); return results; } }); }
@SuppressWarnings("unchecked") public List<User> getUsers() { final Session session = openSession(); session.getTransaction().begin(); // Note: Can use multiple associations with JOIN fetch mode if they are *not*, but results in a cartesian product! final List<User> users = session .createCriteria( User.class ) .setFetchMode( "projectsSubmitted", FetchMode.JOIN ) // .setFetchMode( "projectsOrganized", FetchMode.JOIN ) .list(); session.getTransaction().commit(); return users; }
@SuppressWarnings("unchecked") public List<User> getUsers() { final Session session = openSession(); session.getTransaction().begin(); final List<User> users = session .createCriteria( User.class ) .setFetchMode( "communityMemberships", FetchMode.SELECT ) // not necessary (default) .list(); // init users.get( 0 ).getCommunityMemberships().size(); users.get( 1 ).getCommunityMemberships().size(); session.getTransaction().commit(); return users; }
private static void runStatefulCriteria() throws Exception { Stopwatch watch = Stopwatch.createStarted(); Session session = sessionFactory.openSession(); try { session.getTransaction().begin(); @SuppressWarnings("unchecked") List<Driver> list = session .createCriteria(Driver.class) .setFetchMode("cars", FetchMode.JOIN) .setCacheable(true) .setCacheMode(CacheMode.NORMAL) .list(); for (Driver entry : list) { LOG.info("Entry " + entry.getId()); } session.getTransaction().commit(); } catch (Exception ex) { session.getTransaction().rollback(); throw ex; } finally { session.close(); } LOG.info("StatefulCriteria:=" + watch.toString()); }
@Override public WorkData getWork(int idAddress){ MyLogger.info(log , CLASS_NAME, "getWork", "INIT"); WorkData c = (WorkData) getSessionFactory().getCurrentSession().createCriteria(WorkData.class) .setFetchMode("replyGroups", FetchMode.JOIN) .createAlias("replyGroups", "r", CriteriaSpecification.LEFT_JOIN) .setFetchMode("r.replies", FetchMode.JOIN) // .createAlias("replies", "re", CriteriaSpecification.LEFT_JOIN) // .setFetchMode("re.question", FetchMode.JOIN) .add( Restrictions.idEq(idAddress) ) .uniqueResult(); MyLogger.info(log , CLASS_NAME, "getWork", "END"); return c; }
@Override public WorkData getWorkByAddress(int idAddress){ MyLogger.info(log , CLASS_NAME, "getWorkByAddress", "INIT"); WorkData c0 = null; @SuppressWarnings("unchecked") List<WorkData> c = (List<WorkData>) getSessionFactory().getCurrentSession().createCriteria(WorkData.class) .setFetchMode("replyGroups", FetchMode.JOIN) .createAlias("replyGroups", "r", CriteriaSpecification.LEFT_JOIN) .setFetchMode("r.replies", FetchMode.JOIN) .add(Restrictions.eq("address.idaddress",idAddress)) .addOrder(Order.desc("dateCreated")) .list(); if (!c.isEmpty()) c0 = c.get(0); MyLogger.info(log , CLASS_NAME, "getWorkByAddress", "END"); return c0; }