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)
|