[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-1626) nullpointer on hql query using objects with many-to-one assosiation which contains formula columns

Jens Bornemann (JIRA) noreply at atlassian.com
Fri Oct 10 14:22:04 EDT 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1626?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=31376#action_31376 ] 

Jens Bornemann commented on HHH-1626:
-------------------------------------

Ran into the same problem and fixed it today... (see this patch)...
Index: project/core/src/main/java/org/hibernate/persister/entity/AbstractPropertyMapping.java
===================================================================
RCS file: 
/project/core/src/main/java/org/hibernate/persister/entity/AbstractPropertyMapping.java,v
retrieving revision 1.1
diff -u -r1.1 AbstractPropertyMapping.java
--- project/core/src/main/java/org/hibernate/persister/entity/AbstractPropertyMapping.java	10 Oct 2008 16:56:57 -0000	1.1
+++ project/core/src/main/java/org/hibernate/persister/entity/AbstractPropertyMapping.java	10 Oct 2008 16:59:04 -0000
@@ -178,7 +178,7 @@
 			}
 		}
 		else if ( type.isEntityType() ) {
-			initIdentifierPropertyPaths( path, (EntityType) type, columns, factory );
+			initIdentifierPropertyPaths( path, (EntityType) type, columns, formulaTemplates, factory );
 		}
 	}
 
@@ -186,6 +186,7 @@
 			final String path,
 			final EntityType etype,
 			final String[] columns,
+			final String[] formulaTemplates,
 			final Mapping factory) throws MappingException {
 
 		Type idtype = etype.getIdentifierOrUniqueKeyType( factory );
@@ -195,15 +196,15 @@
 		if ( etype.isReferenceToPrimaryKey() ) {
 			if ( !hasNonIdentifierPropertyNamedId ) {
 				String idpath1 = extendPath(path, EntityPersister.ENTITY_ID);
-				addPropertyPath(idpath1, idtype, columns, null);
-				initPropertyPaths(idpath1, idtype, columns, null, factory);
+				addPropertyPath(idpath1, idtype, columns, formulaTemplates);
+				initPropertyPaths(idpath1, idtype, columns, formulaTemplates, factory);
 			}
 		}
 
 		if (idPropName!=null) {
 			String idpath2 = extendPath(path, idPropName);
-			addPropertyPath(idpath2, idtype, columns, null);
-			initPropertyPaths(idpath2, idtype, columns, null, factory);
+			addPropertyPath(idpath2, idtype, columns, formulaTemplates);
+			initPropertyPaths(idpath2, idtype, columns, formulaTemplates, factory);
 		}
 	}


> nullpointer on hql query using objects with many-to-one assosiation which contains formula columns
> --------------------------------------------------------------------------------------------------
>
>                 Key: HHH-1626
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1626
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core, query-hql
>    Affects Versions: 3.1.3
>         Environment: hibernate 3.1.3
> mysql 4.x
>            Reporter: axel becker
>            Priority: Critical
>         Attachments: OrgResource.hbm.xml
>
>
> -using the attached mapping
> -executing this query: "from OrgResource as o where o.orgCategory.comp_id.companyId= :companyId and  o.orgCategory.comp_id.categoryId= :categoryId "
> results this exception:
> java.lang.NullPointerException
> 	at org.hibernate.persister.entity.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:68)
> 	at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:31)
> 	at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1257)
> 	at org.hibernate.hql.ast.tree.FromElementType.toColumns(FromElementType.java:317)
> 	at org.hibernate.hql.ast.tree.FromElementType.toColumns(FromElementType.java:290)
> 	at org.hibernate.hql.ast.tree.FromElement.toColumns(FromElement.java:376)
> 	at org.hibernate.hql.ast.tree.DotNode.getColumns(DotNode.java:97)
> 	at org.hibernate.hql.ast.tree.DotNode.initText(DotNode.java:210)
> 	at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:204)
> 	at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:94)
> 	at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:90)
> 	at org.hibernate.hql.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:725)
> 	at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1215)
> 	at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4032)
> 	at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3518)
> 	at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1758)
> 	at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1683)
> 	at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:776)
> 	at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:577)
> 	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:218)
> 	at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158)
> 	at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)
> 	at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)
> 	at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
> 	at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
> 	at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
> 	at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
> 	at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)
> i debugged the toColumns Mehtod and found the reason for the nullpointer. the formulaTemplatesByPropertyPath map doesnt contains an entry for "orgCategory.comp_id.companyId" which is the, as formula, mapped column.
> in my opinion the bug is in the initPropertyPaths method. the "if ( type.isAssociationType() ) {" section never checks for formular columns

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