-->
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.  [ 3 posts ] 
Author Message
 Post subject: NPE when using One to One relationship
PostPosted: Tue Nov 24, 2009 6:21 pm 
Newbie

Joined: Tue Nov 24, 2009 6:06 pm
Posts: 2
Hello, I am new to the forums and thought i would seek some help on this issue that i have been experiencing for about 2 days now. Hopefully someone has encountered such an issue.

Here is the scenario. I have the two oracle tables.
Using JBoss 4 and JPA 1.0

Car
This Entity has many fields and getters and setters but the important one is this one
Code:
        @Id
   @Column(name = "CAR_ID", unique = true, nullable = false, precision = 10, scale = 0)
   public long getCarId() {
      return this.carId;
   }

       @OneToOne(fetch = FetchType.LAZY, mappedBy = "car")
   public CarStatus getCarStatus() {
      return this.carStatus;
   }


CarStatus
Another entity containing several fields and getters and setters but here are the important ones.
Code:
@GenericGenerator(name = "generator", strategy = "foreign", parameters = @Parameter(name = "property", value = "car"))
   @Id
   @GeneratedValue(generator = "generator")
   @Column(name = "CAR_ID", unique = true, nullable = false, precision = 10, scale = 0)
   public long getCarId() {
      return this.carId;
   }

        @OneToOne(fetch = FetchType.LAZY)
   @PrimaryKeyJoinColumn
   @NotNull
   public Car getCar() {
      return this.car;
   }




As you can see the CarStatus table has a primary key which is also a foreign key to the Car table.
Does anyone here see why i keep getting the following stacktrace on deployment of the persistent unit?


I have the following exception

Code:
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:296)
   at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
   at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1233)
   at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
   at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:869)
   at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:407)
   at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:126)
   at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:246)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.jboss.ejb3.ServiceDelegateWrapper.startService(ServiceDelegateWrapper.java:103)
   at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
   at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
   at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)


Top
 Profile  
 
 Post subject: Re: NPE when using One to One relationship
PostPosted: Wed Nov 25, 2009 6:48 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
I don't know if there has to be a mappedby on a primaryKeyJoinColumn, please try without it. Don't forget to set optional=false in OneToOne for true lazy loading.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: NPE when using One to One relationship
PostPosted: Wed Nov 25, 2009 11:08 am 
Newbie

Joined: Tue Nov 24, 2009 6:06 pm
Posts: 2
mmerder wrote:
I don't know if there has to be a mappedby on a primaryKeyJoinColumn, please try without it. Don't forget to set optional=false in OneToOne for true lazy loading.


Alas, still the same error :(


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.