We're updating the issue view to help you get more done. 

@Id @OneToOne cause NullPointerException during query

Description

I've two entities, Person and PersonInfo, with a one-to-one relation:

Person.java

1 2 3 4 5 6 7 8 9 10 11 12 13 14 @Entity public class Person { @Id private Integer id; @Basic private String name; @OneToOne( mappedBy = "id" ) private PersonInfo personInfo; ...getters&setters... }

PersonInfo.java

1 2 3 4 5 6 7 8 9 10 11 12 @Entity public class PersonInfo { @Id @OneToOne private Person id; @Basic private String info; ...getters&setters... }

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

Environment

Hibernate 4.0.0.CR5, PostgreSQL 9.1.1, Glassfish 3.1.1

Status

Assignee

Brett Meyer

Reporter

AG

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

4.0.0.CR5
3.6.8

Priority

Major