-->
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.  [ 5 posts ] 
Author Message
 Post subject: NullPointerException whith simple many-to-one association
PostPosted: Tue Feb 21, 2006 5:19 pm 
Newbie

Joined: Tue Feb 21, 2006 4:03 pm
Posts: 10
Hi,

I am a hibernate newbi. Currently, I am trying to read rows from a table "journal". This table has a foreign key link to another table "publisher"
(thus a classical many-to-one association).

Doing so, a NullPointerException is throws.
However, the program works if i delete the many-to-one from the mapping file (naturally iwithout the desired link to a publisher entry).
Thats why i guess that something is wrong with my association mapping or the persistent class object. (or even with the database tables).

Do you have any ideas?

Here the putativly relevant code:

Journal class

Code:
public class Journal{
   public Journal(){}
   private long id;
   private String name;
   /**
    * The Publisher of the journal
    */
   private Publisher publisher = new Publisher();
       // setters and getters
      ...
}



Publisher class

Code:
public class Publisher{
   public Publisher(){}
   private long id;
   private String name;
        priavte String address;
       // setters and getters
      ...
}



Journal mapping

Code:
<class name="Journal"
          table="journal"
          schema="pblc">
      <id name="id" column="id" type="long">
      <generator class="sequence">
            <param name="sequence">pblc.journal_id_seq</param>
         </generator>
      </id>
      <property name="name" .../>
      <many-to-one 
            name="publisher"
            column="publisher_id"/>
   </class>


PostgreSQL tables
Code:
CREATE TABLE pblc.publisher
(
   id      SERIAL PRIMARY KEY,
   name   VARCHAR(50),
   address VARCHAR(50)
);

-- table for a scientific journal
CREATE TABLE pblc.journal
(
   id      SERIAL PRIMARY KEY,
   name    varchar(100),
   publisher_id INTEGER REFERENCES pblc.publisher (id) ON DELETE RESTRICT,
);


And last the first few lines of the error
Quote:
Exception in thread "main" java.lang.NullPointerException
at java.lang.Object.getClass() (/usr/lib/libgcj.so.6.0.0)
at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(java.io.Serializable, org.hibernate.engine.SessionImplementor) (Unknown Source)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(java.io.Serializable, org.hibernate.engine.SessionImplementor) (Unknown Source)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(org.hibernate.event.LoadEvent, org.hibernate.persister.entity.EntityPersister, org.hibernate.engine.EntityKey, org.hibernate.event.LoadEven
[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 10:31 am 
Newbie

Joined: Tue Feb 21, 2006 4:03 pm
Posts: 10
My problem is still unsolved. I tried (i think) everything.
Implementing hashCode() and equals(),
Deleted the foreign key constraint in the database,
called the no-argument-constructor of "Publisher"
in the Journal-class and so on..

Do anyone have a great idea?

Thanx,
Rainer.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 11:00 am 
Newbie

Joined: Tue Feb 21, 2006 6:43 pm
Posts: 4
Try this

<many-to-one
name="publisher"
class="Publisher"
column="publisher_id"/>


and in your Journal Class just have

private Publisher publisher

and have getter and setter for it.

In your mapping u have to mention the class your using.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 11:35 am 
Newbie

Joined: Tue Feb 21, 2006 4:03 pm
Posts: 10
thank you, but it still does not work.

Look at my code, there still was a private Publisher attribute
in Journal. And mentioning the class was one thing I tried before
and now again, without any effect.

Bye,
Rainer.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 1:59 pm 
Newbie

Joined: Tue Feb 21, 2006 4:03 pm
Posts: 10
I had a look at previous log4-messages (previous to the shitty NullPointerException.

It turns out that for every persistent class there is a
message like
12219 [main] ERROR org.hibernate.proxy.BasicLazyInitializer - CGLIB
Quote:
Enhancement failed: zenodot.database.entities.Journal
java.lang.NoClassDefFoundError: net.sf.cglib.proxy.Enhancer
at java.lang.Class.initializeClass() (/usr/lib/libgcj.so.6.0.0)
at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(java.lang.Class, java.lang.Class[]) (Unknown Source)
at org.hibernate.proxy.CGLIBProxyFactory.postInstantiate(java.lang.String, java.lang.Class, java.util.Set, java.lang.reflect.Method, java.lang.reflect.Method, org.hibernate.type.AbstractComponentType) (Unknown Source)
at org.hibernate.tuple.PojoEntityTuplizer.buildProxyFactory(org.hibernate.mapping.PersistentClass, org.hibernate.property.Getter, org.hibernate.property.Setter) (Unknown Source)
at org.hibernate.tuple.AbstractEntityTuplizer.AbstractEntityTuplizer(org.hibernate.tuple.EntityMetamodel, org.hibernate.mapping.PersistentClass) (Unknown Source)
at org.hibernate.tuple.PojoEntityTuplizer.PojoEntityTuplizer(org.hibernate.tuple.EntityMetamodel, org.hibernate.mapping.PersistentClass) (Unknown Source)
at org.hibernate.tuple.TuplizerLookup.create(org.hibernate.mapping.PersistentClass, org.hibernate.tuple.EntityMetamodel) (Unknown Source)
at org.hibernate.tuple.EntityMetamodel.EntityMetamodel(org.hibernate.mapping.PersistentClass, org.hibernate.engine.SessionFactoryImplementor) (Unknown Source)
at org.hibernate.persister.entity.AbstractEntityPersister.AbstractEntityPersister(org.hibernate.mapping.PersistentClass, org.hibernate.cache.CacheConcurrencyStrategy, org.hibernate.engine.SessionFactoryImplementor) (Unknown Source)
at org.hibernate.persister.entity.SingleTableEntityPersister.SingleTableEntityPersister(org.hibernate.mapping.PersistentClass, org.hibernate.cache.CacheConcurrencyStrategy, org.hibernate.engine.SessionFactoryImplementor, org.hibernate.engine.Mapping) (Unknown Source)
at org.hibernate.persister.PersisterFactory.createClassPersister(org.hiberna


It seems that there is no net.sf.cglib.proxy.Enhancer.

However, there is such a class in cglib-2.1.3.jar which I have in my class path.

How that comes?


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