[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2978) Using HQL index() on a <index-many-to-many..> key in a <map...> cannot dereference any properties of the key - java.lang.NullPointerException

James Andrews (JIRA) noreply at atlassian.com
Mon Dec 3 08:39:57 EST 2007


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2978?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_29026 ] 

James Andrews commented on HHH-2978:
------------------------------------

Test case, tested with Hibernate 2.5.2 GA, JDK 1.5, MySQL 5.0.27 NT

------------------------------------------------------------------------------------------------

DB Schema:

------------------------------------------------------------------------------------------------

CREATE TABLE parentnode (
    id                            INT UNSIGNED NOT NULL,
    name                     VARCHAR(45) NOT NULL,
    CONSTRAINT PRIMARY KEY (id)
)

CREATE TABLE indexnode (
    id                            INT UNSIGNED NOT NULL,
    name                     VARCHAR(45) NOT NULL,
    CONSTRAINT PRIMARY KEY (id)
)

CREATE TABLE childnode
(
    id                             INT UNSIGNED NOT NULL,
    indexNodeId          INT UNSIGNED NOT NULL,
    value                       INT UNSIGNED NOT NULL,
    CONSTRAINT fkChiildNodeParent FOREIGN KEY (id) REFERENCES parentnode (id),
    CONSTRAINT fkChildNodeIndex FOREIGN KEY (indexNodeId) REFERENCES indexnode (id),
    CONSTRAINT PRIMARY KEY (id, indexNodeId)
)

------------------------------------------------------------------------------------------------

Java sources:

------------------------------------------------------------------------------------------------

intranet/test/ParentNode.java:

------------------------------------------------------------------------------------------------
package intranet.test;



import java.util.Map;



public class ParentNode {


	private Long								id;

	private String								name;

	private Map<IndexNode, Integer>	children;


	public Long getId() {
		return id;
	}


	public void setId(Long id) {
		this.id = id;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public Map<IndexNode, Integer> getChildren() {
		return children;
	}


	public void setChildren(Map<IndexNode, Integer> children) {
		this.children = children;
	}


}

------------------------------------------------------------------------------------------------

intranet/test/IndexNode.java:

------------------------------------------------------------------------------------------------


package intranet.test;



public class IndexNode {


	private Long	id;

	private String	name;


	public Long getId() {
		return id;
	}


	public void setId(Long id) {
		this.id = id;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}

}

------------------------------------------------------------------------------------------------

Mapping file: Test.hbm.xml

------------------------------------------------------------------------------------------------

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="intranet.test">


	<class name="intranet.test.IndexNode"
		table="test.indexnode">
		<id column="id" type="long" name="id">
			<generator class="native" />
		</id>
		
		<property name="name" type="string" />
	</class>


	<class name="intranet.test.ParentNode"
		table="test.parentnode">
		<id column="id" type="long" name="id">
			<generator class="native" />
		</id>

		<property name="name" type="string" />

		<map name="children"
			table="test.childnode">
			<key column="id" />

			<index-many-to-many class="intranet.test.IndexNode"
				column="indexNodeId" />
			<element column="value" type="int" />
		</map>

	</class>


</hibernate-mapping>

------------------------------------------------------------------------------------------------

Failing HQL:

------------------------------------------------------------------------------------------------

Anything that references a property of the index class (IndexNode), such as:

select parent, index(child).name, child
from ParentNode parent
left join parent.children child

Stack trace as above for this query.
------------------------------------------------------------------------------------------------

Queries fetching the index itself, rather than a property of it, such as:

select parent, index(child), child
from ParentNode parent
left join parent.children child

do actually fetch instances of "IndexNode", and work fine, the problem only occurs when trying to fetch a property of the index instance.


> Using HQL index() on a <index-many-to-many..> key in a <map...> cannot dereference any properties of the key - java.lang.NullPointerException
> ---------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HHH-2978
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2978
>             Project: Hibernate3
>          Issue Type: Bug
>          Components: query-hql
>    Affects Versions: 3.2.5
>         Environment: Hibernate 3.2.5 GA, MySQL 5.0.27 Community NT, Eclipse 3.1.1, Hibernate Tools 3.2 beta 9
>            Reporter: James Andrews
>
> As mentioned in summary, using a mapped POJO as the index of a <map..> relationship, via the <index-many-to-many class="..> approach.
> Using a table join, for instance:
> select index(depts), depts
> from ModificationFixed fixed
> left join fixed.departments depts
> Will fetch Department instances for each value, but if you instead try to fetch a property of the index:
> select index(depts).name, depts
> from ModificationFixed fixed
> left join fixed.departments depts
> then this causes the aforementioned NullPointerException, both in the hibernate tools preview, and in practise when trying to execute the query, with the following stack trace:
> Exception in thread "main" java.lang.NullPointerException
> 	at org.hibernate.hql.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:444)
> 	at org.hibernate.hql.antlr.HqlSqlBaseWalker.propertyRef(HqlSqlBaseWalker.java:1080)
> 	at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:1881)
> 	at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:1825)
> 	at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1394)
> 	at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:553)
> 	at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
> 	at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
> 	at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
> 	at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
> 	at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
> 	at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
> 	at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
> 	at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
> 	at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
> 	at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:115)
> 	at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
> 	at intranet.db.PersistentMySQL.createQueryArray(PersistentMySQL.java:154)
> 	at intranet.budget.planner.ModificationFixed.main(ModificationFixed.java:165)

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