Open Source Support Tools
 
Search Item
 
Summary
  Reported Issue
Title: [ANN-554] NPE with @Id on @OneToOne
Project: annotations
Item Last Modified: Fri, 27 Jun 2008 04:22:09 -0500 (CDT)
Tags:  
 
 
3.2.2 Bug annotationconfiguration annotations cascade caused cfg class configurationtask ejb ejb3configuration eventlistenerconfigurator exception fixed foo forum hbm2ddlexportertask hibernate hibernate-3.2 hibernate-annotations hibernate-annotations-3.2 hibernatepersistence hibernatetooltask href id issue java.lang.nullpointerexception key lang leads level long mappedby npe null nullable onetoone onetoonesecondpass org postgresql postgresql-7.4 primary public references something stringhelper util workaround
Details
[ANN-554] NPE with @Id on @OneToOne
Reporter:   Loïc Minier
Created:   Mon, 12 Feb 2007 08:04:50 -0600 (CST)
Updated:   Fri, 27 Jun 2008 04:22:09 -0500 (CDT)
Key:   ANN-554
Versions:   Not provided
Environment:   Hibernate 3.2.2 GA, Hibernate Annotations 3.2.1, J2SE 1.6.0-b105 on Debian GNU/Linux sid, PostgreSQL 7.4
Priority:   4
Status:   Resolved
Resolution:   Fixed
Original Link:   http://opensource.atlassian.com/projects/hibernate/browse/ANN-554
Summary:   NPE with @Id on @OneToOne
Description:
Hi,

(Note: I originally reported this on the forum, but the lack of response suggests this might be a bug in Hibernate Annotations or Hibernate; the forum topic is at: <a href="http://forum.hibernate.org/viewtopic.php?t=970823)">http://forum.hibernate.org/viewtopic.php?t=970823)</a>

I hope it's not a misuse of Hibernate, but I'm trying to use @Id on @OneToOne, and this causes the following NPE when running hbm2ddl:
java.lang.NullPointerException
at org.hibernate.util.StringHelper.qualify(StringHelper.java:264)
at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:196)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1130)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:296)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:56)
at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:287)
at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:45)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:171)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.apache.tools.ant.Main.runBuild(Main.java:668)
at org.apache.tools.ant.Main.startAnt(Main.java:187)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)


What I'm trying to do at the application level is:
Foo class and table
long foo_id, primary key
FooData fooData, nulllable=true


FooData class and table
foo_id references Foo(foo_id), nullable=false


This is expressed in Java as:
@Entity
@Table(name = "foo")
public class Foo {
@Id @GeneratedValue
@Column(name = "foo_id")
Long id;

@OneToOne(mappedBy = "foo", cascade = CascadeType.ALL)
FooData fooData;
...
@Entity
@Table(name = "foo_data")
public class FooData {
@Id
@OneToOne
@JoinColumn(name = "foo_id", nullable = false)
Foo foo;


This causes a NPE here.

If I use a real Id on FooData, e.g.:
@Id
@Column(name = "foo_data_id")
Long id;

it works, and I end up with:
- foo_id in table foo as a primary key
- foo_data_id in table foo_data as a primary key
- foo_id in table foo_data not null
- foo_id in table foo_data references foo_id in table foo

I don't want a foo_data_id, I don't need it, hence the lack of it which leads to the NPE.

Bye,
Comments:
emmanuel Mon, 12 Feb 2007 08:31:28 -0600 (CST)
Answered on the forum post. I need to fix the NPE though
emmanuel Mon, 12 Feb 2007 23:19:45 -0600 (CST)
happens even witht he described workaround apparently, need to have a look at it
lool Tue, 6 Mar 2007 09:21:44 -0600 (CST)
I personally still experience the issue -- but only with the mappedBy OneToOne, not if I remove it --, and was not able to locate the fix you committed by looking at http://anonsvn.jboss.org/repos/hibernate/trunk/HibernateExt nor in http://anonsvn.jboss.org/repos/hibernate/trunk/Hibernate3; could you point me to the fix?

Thanks!
emmanuel Tue, 6 Mar 2007 11:21:23 -0600 (CST)
http://anonsvn.jboss.org/repos/hibernate/Branch_3_2/HibernateExt
syvalta Fri, 23 Mar 2007 07:52:56 -0500 (CDT)
Something probably related to this bug. I'm quite sure I have misconfigured something, but I get the following error when using OneToOne mappings. Failing more gracefully would be nice.

Caused by: javax.persistence.PersistenceException: java.lang.NullPointerException
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:258)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
... 39 more
Caused by: java.lang.NullPointerException
at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:135)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1130)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:316)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1265)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:150)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:884)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:186)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:246)
... 43 more
benjamin morelle Fri, 27 Jun 2008 04:22:08 -0500 (CDT)
I have the same exception when I have a "mapped by" not correct.