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 classCode:
public class Publisher{
public Publisher(){}
private long id;
private String name;
priavte String address;
// setters and getters
...
}
Journal mappingCode:
<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 tablesCode:
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]