[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3689) NPE when using composite-map-key and composite-element together in a map

Hepoi Ko (JIRA) noreply at atlassian.com
Tue Apr 7 22:32:37 EDT 2009


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

Hepoi Ko commented on HHH-3689:
-------------------------------

I experience same problem using Hibernate 3.3.1.GA (on DB2 AS400) with XML Mapping, using formula within many-to-one and composite-element

I read the source code org.hibernate.loader.JoinWalker, and I make some changes and seem work fine.

within the walkCompositeElementTree() method line 522

				// simple, because we can't have a one-to-one or a collection 
				// (or even a property-ref) in a composite-element:
//				String[] aliasedLhsColumns = StringHelper.qualify(alias, lhsColumns);
				String[] fullAliasedLhsColumns = persister.getElementColumnNames(alias);
				String[] aliasedLhsColumns = ArrayHelper.slice(fullAliasedLhsColumns, begin, length);

by commenting original line "String[] aliasedLhsColumns = StringHelper.qualify(alias, lhsColumns);", then add following 2 lines

				String[] fullAliasedLhsColumns = persister.getElementColumnNames(alias);
				String[] aliasedLhsColumns = ArrayHelper.slice(fullAliasedLhsColumns, begin, length);

The table that is mapped to, is only used for immuture table (read-only), so I guess it would work fine for me. Not sure if this "trick" would apply for update, insert or delete operation.

If anyone from Hibernate can confirm this, it would be great.

I hope this help.

> NPE when using composite-map-key and composite-element together in a map
> ------------------------------------------------------------------------
>
>                 Key: HHH-3689
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3689
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.3.1
>         Environment: 3.3.1, MySQL 5
>            Reporter: Jason Maskell
>
> When trying to get a composite map key working with my composite element class, I ran into this issue. I've seen it reported in a couple of other places since August 08, so it's been around for a while.
> 		<map name="inventory" table="capo_inventory">
>  			<key column="capo_id"/>
> 			<composite-map-key class="ItemCountKey">
> 				<key-many-to-one name="item" column="item_id" class="Item"/>
> 				<key-property name="quality" type="int" column="quality" />
> 			</composite-map-key>
> 			<composite-element class="ItemCount">
> 				<many-to-one name="item" class="com.tamedtornado.data.Item"
> 					formula="item_id" />
> 				<property name="quality" formula="quality" type="int" />
> 				<property name="count" type="int" />
> 			</composite-element>
>  		</map>
> This mapping causes this error (root cause):
> Caused by: java.lang.NullPointerException
> 	at org.hibernate.util.StringHelper.qualify(StringHelper.java:287)
> 	at org.hibernate.util.StringHelper.qualify(StringHelper.java:301)
> 	at org.hibernate.loader.JoinWalker.walkCompositeElementTree(JoinWalker.java:522)
> 	at org.hibernate.loader.JoinWalker.walkCollectionTree(JoinWalker.java:333)
> 	at org.hibernate.loader.JoinWalker.walkCollectionTree(JoinWalker.java:278)
> 	at org.hibernate.loader.collection.BasicCollectionJoinWalker.<init>(BasicCollectionJoinWalker.java:70)
> 	at org.hibernate.loader.collection.BasicCollectionLoader.<init>(BasicCollectionLoader.java:76)
> 	at org.hibernate.loader.collection.BasicCollectionLoader.<init>(BasicCollectionLoader.java:63)
> 	at org.hibernate.loader.collection.BasicCollectionLoader.<init>(BasicCollectionLoader.java:54)
> 	at org.hibernate.loader.collection.BatchingCollectionInitializer.createBatchingCollectionInitializer(BatchingCollectionInitializer.java:115)
> 	at org.hibernate.persister.collection.BasicCollectionPersister.createCollectionInitializer(BasicCollectionPersister.java:320)
> 	at org.hibernate.persister.collection.AbstractCollectionPersister.postInstantiate(AbstractCollectionPersister.java:563)
> 	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:326)
> 	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
> 	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:814)
> 	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:732)
> 	at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
> 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
> 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
> 	... 65 more
> It's quite easy to debug, but I have no idea what it's supposed to be doing, so have no idea how to fix it. The String[] cols parameter passed into walkCompositeElementTree has two nulls in it, which causes the NPE later in the stack. I hope this is easily reproducible, as I'm going to have to write some really grodey code now that I can't easily find my object by those two parameters. :)

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