-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Any idea why this simple code throws a NPE ?
PostPosted: Fri Feb 16, 2007 7:20 pm 
Newbie

Joined: Fri Feb 16, 2007 7:13 pm
Posts: 6
Hi,

I am relatively new to Hibernate annotations, and while I think it is quite a good product I have been puzzled all day today over why this simple code throws a NullPointerException:

Code:
import java.io.Serializable;

import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.OneToOne;
import javax.persistence.Table;


@Entity
@IdClass(TestPK.class)
@Table(name = "TEST")
public class Test implements Serializable {
    private String test;

    @Id
    @OneToOne
    public String getTest() {
        return test;
    }

    public void setTest(String test) {
        this.test = test;
    }
}


@Embeddable
class TestPK implements Serializable {
    private String test;
   
    @OneToOne
    public String getTest() {
        return test;
    }

    public void setTest(String test) {
        this.test = test;
    }
}



The exception:
Code:
java.lang.NullPointerException
        at org.hibernate.cfg.AnnotationBinder.bindOneToOne(AnnotationBinder.java
:1867)
        at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(Annotati
onBinder.java:1286)
        at org.hibernate.cfg.AnnotationBinder.fillComponent(AnnotationBinder.jav
a:1662)
        at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:1695)

        at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:66
0)
        at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(Anno
tationConfiguration.java:452)
        at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(Annotatio
nConfiguration.java:268)
        at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1039
)
        at org.codehaus.mojo.hibernate3.configuration.AbstractComponentConfigura
tion.getConfiguration(AbstractComponentConfiguration.java:38)
        at org.codehaus.mojo.hibernate3.exporter.Hbm2DDLExporterMojo.doExecute(H
bm2DDLExporterMojo.java:87)
        at org.codehaus.mojo.hibernate3.HibernateExporterMojo.execute(HibernateE
xporterMojo.java:139)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi
nManager.java:412)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
ultLifecycleExecutor.java:534)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandalone
Goal(DefaultLifecycleExecutor.java:488)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Defau
ltLifecycleExecutor.java:458)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHan
dleFailures(DefaultLifecycleExecutor.java:306)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmen
ts(DefaultLifecycleExecutor.java:273)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi
fecycleExecutor.java:140)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:256)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)

        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)



This error happens when I try to generate the schema using hbm2ddl plugin for maven so I don't know if it's hibernate related or plugin related. I don't get the above exception when I change the association from OneToOne to something else.
My actual code is a bit more complicated than this (I am trying to use a composite primary key), but I reproduced the same problem with the above simple code. Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 20, 2007 7:37 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I fix some issues regarding that:
http://opensource.atlassian.com/projects/hibernate/browse/ANN-554
http://opensource.atlassian.com/projects/hibernate/browse/ANN-556

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.