-->
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: many-to-one problem - NullPointerException only while loadin
PostPosted: Wed May 03, 2006 7:55 pm 
Newbie

Joined: Wed May 03, 2006 7:35 pm
Posts: 2
Location: Canada
I'm having problems with a many-to-one mapping between two entities: CuttingSheet and Site. I can insert/delete/update the entities without any problems but when I try to load it I'm getting a NullPointerException from somewhere within Hibernate.

Some background:
- Hibernate 3.1.3
- launching from within Eclipse 3.1.2 but everyting is in one project
and all the hibernate libraries are in the project's classpath so it
is not a class loader problem between bundles
- XDoclet 1.2.3
- PostgreSQL 8.1.2 with 8.1 JDBC3 driver

The relevant portion of the CuttingSheet class:

public class CuttingSheet
{
/**
* @hibernate.many-to-one
* column="fk_site"
* not-null="false"
* outer-join="false"
* access="field"
*/
public Site getSite()
{
return this.site;
}

public void setSite(Site site)
{
Site old = this.site;
this.site = site;
firePropertyChange(P_SITE, old, site);
}
}

This generates the following mapping (just the relevant portion extracted):
<many-to-one
name="site"
class="com.vanbelle.plantarium.data.entity.Site"
cascade="none"
outer-join="false"
update="true"
insert="true"
access="field"
column="fk_site"
not-null="false"
/>

The table created is like this:
Table prd_cutting_sheet:
pk - bigint not null
sheet_no - character varying(255)
qty_cut - bigint
fk_cutter - bigint
cut_date - timestamp with timezone
fk_site - bigint

Indexes:
"prd_cutting_sheet_pkey" PRIMARY KEY, btree (pk)

Foreign-key constraints:
"fkf62401b330d88996" FOREIGN KEY (fk_site) REFERENCES in_site(pk)
"fkf62401b3ead532d5" FOREIGN KEY (fk_cutter) REFERENCES employee(pk)

I'm trying to load using this code executed from within a seperate thread:

Session session = ConnectionManager.getSession();
Transaction tx = session.beginTransaction();

CuttingSheet sheet = null;

try
{
Query q = session.createQuery("from CuttingSheet cs where cs.sheetNo = :fsheetNo");
q.setString("fsheetNo", sheetNo);
List result = q.list();
Iterator iter = result.iterator();
if (iter.hasNext())
{
sheet = (CuttingSheet) iter.next();
}
}
catch (Exception e)
{
e.printStackTrace();
}

tx.commit();
session.close();

Hibernate generates this SQL:
select
cuttingshe0_.pk as pk1_,
cuttingshe0_.sheet_no as sheet2_1_,
cuttingshe0_.qty_cut as qty3_1_,
cuttingshe0_.fk_cutter as fk4_1_,
cuttingshe0_.cut_date as cut5_1_,
cuttingshe0_.fk_site as fk6_1_
from
prd_cutting_sheet cuttingshe0_
where
cuttingshe0_.sheet_no=?

Similar code for adding, deleting or updating the table works fine.

When I run it this I get an exception like this:
java.lang.NullPointerException
at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3121)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:232)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:173)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:830)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
at org.hibernate.type.EntityType.resolve(EntityType.java:303)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.vanbelle.plantarium.client.swing.perspective.cuttingsheet.job.LoadSheetJob.runInThread(LoadSheetJob.java:34)
at com.vanbelle.plantarium.client.job.Job.run(Job.java:60)


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 9:24 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The most likely explanation is that your firePropertyChange doesn't check for null values. When the CuttingSheet object is being initialized by Hibernate, setSite(site) will be called on an object with a null site, and you (presumably) won't want to fire any property changes in that case.

_________________
Code tags are your friend. Know them and use them.


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.