[hibernate-issues] [Hibernate-JIRA] Created: (HHH-2871) can't specify property of the element in the collection

Vlad Rechkalov (JIRA) noreply at atlassian.com
Tue Oct 2 02:24:24 EDT 2007


can't specify property of the element in the collection
-------------------------------------------------------

                 Key: HHH-2871
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2871
             Project: Hibernate3
          Issue Type: Bug
          Components: query-sql
    Affects Versions: 3.2.5
            Reporter: Vlad Rechkalov
         Attachments: SQLQueryParser.java

In according to Hibernate documentation (topic 16.1.4.1. Alias and property references) collection properties can be specified a few ways:

All properties of the the collection                             {[aliasname].*}
All properties of the element in the collection        {[aliasname].element.*}
Property of the element in the collection                 {[aliasname].element.[propertyname]}

But the last way doesn't work.

Example:

There are two entities: Program and Document. Program has one-to-many inverse collection of Documents.

Program
  int getId()
  List<Document> getDocuments()	// one-to-many inverse collection

Document
  int getId()
  String getTitle()
  Program getParent()		// many-to-one association

Trying to select Program and fetch collection of Documents:

select
  p.id as {p.id},
  d.program_id as {d.key},
  d.id as {d.element},
  d.id as {d.element.id},
  d.title as {d.element.title},
  d.program_id as {d.element.program}
from ...

SQLQuery q = session.createSQLQuery
q.addEntity("p", Program.class);
q.addJoin("d", "p.documents");
q.list();                                                                  // throws exception


There is a simple way to fix this bug:

class SQLQueryParser
method resolveCollectionProperties

instead of code (line 140)

	else if ( "element.*".equals( propertyName ) ) {
		return resolveProperties( aliasName, "*" );
	}

write

	else if( propertyName.startsWith(ELEMENT_PREFIX) ) {
		return resolveProperties( aliasName, propertyName.substring(ELEMENT_PREFIX.length()) );
	}

comments: ELEMENT_PREFIX is defined as

	private static final String ELEMENT_PREFIX = "element.";


The fixed file is attached.


-- 
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