[hibernate-issues] [Hibernate-JIRA] Created: (HSEARCH-305) Hibernate search doesn't work with criteria when it is not initialized laziily

prabhu lal (JIRA) noreply at atlassian.com
Mon Nov 24 00:26:15 EST 2008


Hibernate search doesn't work with criteria when it is not initialized laziily
------------------------------------------------------------------------------

                 Key: HSEARCH-305
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-305
             Project: Hibernate Search
          Issue Type: Bug
          Components: query
    Affects Versions: 3.0.1.GA
         Environment: MYSQL,HIBERNATE 3.0 , Flex with dpHibernate
            Reporter: prabhu lal
         Attachments: QueryLoader.java

For the RIA applications complete object tree should be initialized(To achieve that there is work around available like dpHibernate). But hibernate search doesn't apply criteria to queried result because it returns the result on the basis of wether objectt is intialized by loading the criteria objects.Since there is no lazy intiaialization so all the objects are loaded andcomplete result will be return irrespctive of criteria.
code snipet from Hibernate Search API(org.hibernate.search.engine.QueryLoader.java.):  

	public List load(EntityInfo... entityInfos) {
		final int maxResults = entityInfos.length;
		if ( maxResults == 0 ) return EMPTY_LIST;
		if ( entityType == null ) throw new AssertionFailure( "EntityType not defined" );
		if ( criteria == null ) criteria = session.createCriteria( entityType );

		DocumentBuilder builder = searchFactoryImplementor.getDocumentBuilders().get( entityType );
		String idName = builder.getIdentifierName();
		int loop = maxResults / MAX_IN_CLAUSE;
		boolean exact = maxResults % MAX_IN_CLAUSE == 0;
		if ( !exact ) loop++;
		Disjunction disjunction = Restrictions.disjunction();
		for (int index = 0; index < loop; index++) {
			int max = index * MAX_IN_CLAUSE + MAX_IN_CLAUSE <= maxResults ?
					index * MAX_IN_CLAUSE + MAX_IN_CLAUSE :
					maxResults;
			List ids = new ArrayList( max - index * MAX_IN_CLAUSE );
			for (int entityInfoIndex = index * MAX_IN_CLAUSE; entityInfoIndex < max; entityInfoIndex++) {
				ids.add( entityInfos[entityInfoIndex].id );
			}
			disjunction.add( Restrictions.in( idName, ids ) );
		}
		criteria.add( disjunction );
		criteria.list(); //load all objects

		//mandatory to keep the same ordering
		List result = new ArrayList( entityInfos.length );
		for (EntityInfo entityInfo : entityInfos) {
			Object element = session.load( entityInfo.clazz, entityInfo.id );
			if ( Hibernate.isInitialized( element ) ) { //This is true for all the objects,in case objects are eagrly intialized
				//all existing elements should have been loaded by the query,
				//the other ones are missing ones
				result.add( element );
			}
		}
		return result;
	}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list