[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-6813) @Id @OneToOne cause NullPointerException during query
Alfio (JIRA)
noreply at atlassian.com
Sun Nov 27 05:19:21 EST 2011
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-6813?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=44440#comment-44440 ]
Alfio commented on HHH-6813:
----------------------------
I tried to debug hiberjta test to help you to solve this problem. I compared @Id @OneToOne tecnique with @MapsId one.
The NPE is thrown in AbstractEntityPersister.loadByUniqueKey() because uniqueKeyLoaders map is empty. In the @MapsId case there is one uniqueKeyLoader bound to person property (wich has the @MapsId annotation).
(PS: If I set useStaticLoader to false the test passes, but I don't think this is a solution.)
A uniqueKeyLoader is created scanning properties in entityMetamodel. This happens in AbstractEntityPersister.createUniqueKeyLoader() method. What I noticed is that properties do not include identifier, hence no uniqueKeyLoader can be created for id in @Id @OneToOne case.
I think should be added a routine to add uniqueKeyLoader in the case of @Id @OneToOne. To do so the needed information could be extracted from entityMetamodel.getIdentifierProperty() but in @Id @OneToOne case identifierProperty is not set properly. For example entityMetamodel.getIdentifierProperty().getName() returns null intead of "id".
In PropertyBinder.bind() the control enters in 'if ( isXToMany || entityBinder.wrapIdsInEmbeddedComponents() ) {}' block only in @Id @OneToOne case. There are two FIXME, the problem may be here.
I hope my efforts are usefull.
> @Id @OneToOne cause NullPointerException during query
> -----------------------------------------------------
>
> Key: HHH-6813
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6813
> Project: Hibernate Core
> Issue Type: Bug
> Components: core, entity-manager
> Affects Versions: 3.6.8, 4.0.0.CR5
> Environment: Hibernate 4.0.0.CR5, PostgreSQL 9.1.1, Glassfish 3.1.1
> Reporter: Alfio
> Labels: jpa2
> Attachments: hiberjta.zip, hiberlocal.zip, hibertest.war, hibertest.zip
>
>
> I've two entities, Person and PersonInfo, with a one-to-one relation:
> {code:title=Person.java}
> @Entity
> public class Person {
> @Id
> private Integer id;
> @Basic
> private String name;
> @OneToOne( mappedBy = "id" )
> private PersonInfo personInfo;
> ...getters&setters...
> }
> {code}
> {code:title=PersonInfo.java}
> @Entity
> public class PersonInfo {
> @Id
> @OneToOne
> private Person id;
>
> @Basic
> private String info;
> ...getters&setters...
> }
> {code}
> Hibernate correctly creates two tables but a NPE occours during a simple select query (only if tables have one or more records)
> em.createQuery("SELECT p FROM Person p").getResultList();
> ...
> java.lang.NullPointerException
> at org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:2202)
> at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:661)
> at org.hibernate.type.EntityType.resolve(EntityType.java:441)
> at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:150)
> at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1006)
> at org.hibernate.loader.Loader.doQuery(Loader.java:883)
> at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)
> at org.hibernate.loader.Loader.doList(Loader.java:2463)
> at org.hibernate.loader.Loader.doList(Loader.java:2449)
> at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2279)
> at org.hibernate.loader.Loader.list(Loader.java:2274)
> at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470)
> at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
> at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:196)
> at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1118)
> at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
> at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:252)
> at com.sun.enterprise.container.common.impl.QueryWrapper.getResultList(QueryWrapper.java:195)
> at nogroup.hibertest.Bean.execute(Bean.java:23)
> at nogroup.hibertest.org$jboss$weld$bean-hibertest-1$0-SNAPSHOT-ManagedBean-class_nogroup$hibertest$Bean_$$_WeldClientProxy.execute(org$jboss$weld$bean-hibertest-1$0-SNAPSHOT-ManagedBean-class_nogroup$hibertest$Bean_$$_WeldClientProxy.java)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:601)
> at javax.el.BeanELResolver.invokeMethod(BeanELResolver.java:737)
> at javax.el.BeanELResolver.invoke(BeanELResolver.java:467)
> at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:254)
> at com.sun.el.parser.AstValue.invoke(AstValue.java:228)
> at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
> at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:43)
> at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:56)
> at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
> at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
> ... 33 more
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list