-->
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: NullPointerException
PostPosted: Sat Oct 07, 2006 3:35 am 
Newbie

Joined: Sat Oct 07, 2006 3:01 am
Posts: 2
When I run the following code:

Session session = HibernateUtil.getSession();
ReceiptVoucher receiptVoucher = new ReceiptVoucher();
Criteria criteria = session.createCriteria(receiptVoucher.getClass());
criteria.list();
HibernateUtil.closeSession();


...............
I get the following exception:

Exception in thread "main" java.lang.NullPointerException
at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3232)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:237)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:174)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:86)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:871)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:839)
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.criteria.CriteriaLoader.list(CriteriaLoader.java:95)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1562)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at com.tsd.model.dao.ar.ReceiptVoucherManager.main(ReceiptVoucherManager.java:104)


********************************************************
Does any one has any idea how come I resolve the above problem?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 07, 2006 3:50 am 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
Post the mapping files and the code where you are building the sessionfactory. Have you added the mapping file through Configuration's addResource API?


Top
 Profile  
 
 Post subject: NUllPointerException
PostPosted: Mon Oct 09, 2006 2:04 am 
Newbie

Joined: Sat Oct 07, 2006 3:01 am
Posts: 2
Thanks my problem has resolved, but the same time it has created a confusion for me in my understanding of hibernate. Actually the mapping file of ReceiptVoucher had a <many- to- one> relation ship with another entity AdvanceReceipt, and i had set the fetch mode as 'select', because this attribute in the database table receipt_voucher (having mapping ReceiptVoucher) was nullable, and i didnt need AdvanceReceipt all the time, but whenever any record in the receipt_voucher table had a value in the advance_receipt_id( <many- to- one> relation) attribute, the hibernate was throwing the NullPointerException. setting fetch mode as 'join' solved my problem, but i dont understand why its behaviour like that? Do you have any idea about it? I pasting my mapping files here:


*************************************************************
ReceiptVoucher:
*************************************************************
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jul 25, 2006 6:26:33 PM by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
<class name="com.tsd.model.entitybean.ar.ReceiptVoucher" table="receipt_voucher">
<comment></comment>
<id name="id" type="java.lang.Integer">
<column name="id"/>
<generator class="assigned"/>
</id>
<many-to-one name="employee" class="com.tsd.model.entitybean.ar.AREmployee" fetch="join">
<column name="employee_id" length="10" not-null="false">
<comment></comment>
</column>
</many-to-one>
<many-to-one name="coa" class="com.tsd.model.entitybean.ar.ARCoa" fetch="join">
<column name="coa_id" length="10" not-null="true">
<comment></comment>
</column>
</many-to-one>
<many-to-one name="transactionType" class="com.tsd.model.entitybean.ar.ArTransactionType" fetch="join">
<column name="ar_transaction_type_id" length="10" not-null="true">
<comment></comment>
</column>
</many-to-one>
<many-to-one name="advanceReceipt" class="com.tsd.model.entitybean.ar.AdvanceReceipt" fetch="join">
<column name="advance_receipt_id" length="20">
<comment></comment>
</column>
</many-to-one>

<many-to-one name="customer" class="com.tsd.model.entitybean.ar.ARCustomer" fetch="join">
<column name="customer_id" length="10" not-null="true">
<comment></comment>
</column>
</many-to-one>

<set name="receiptVoucherDetails" lazy="false" inverse="true" fetch="join" cascade="persist,save-update,delete">
<key>
<column name="receipt_voucher_id" not-null="true">
<comment></comment>
</column>
</key>
<one-to-many class="com.tsd.model.entitybean.ar.ReceiptVoucherDetail"/>
</set>
<property name="amount" type="java.lang.Double">
<column name="amount" precision="22" scale="0" not-null="true">
<comment></comment>
</column>
</property>

<property name="receiptMode" type="java.lang.Character">
<column name="receipt_mode" length="1" not-null="true">
<comment></comment>
</column>
</property>

<property name="bankName" type="java.lang.String">
<column name="bank_name" length="50">
<comment></comment>
</column>
</property>

<property name="chequeNo" type="java.lang.String">
<column name="cheque_no" length="15">
<comment></comment>
</column>
</property>

<property name="chequeDate" type="java.util.Date">
<column name="cheque_date">
<comment></comment>
</column>
</property>

<property name="interCompany" type="java.lang.Byte">
<column name="inter_company" length="1" not-null="true">
<comment></comment>
</column>
</property>

<property name="recoveryReceiptNo" type="java.lang.String">
<column name="recovery_receipt_no" length="10">
<comment></comment>
</column>
</property>

<!--<property name="taxAmount" type="java.lang.Double">-->
<!--<column name="tax_amount">-->
<!--<comment></comment>-->
<!--</column>-->
<!--</property>-->


<property name="receiptNo" type="java.lang.String">
<column name="receipt_no" length="10" not-null="true">
<comment></comment>
</column>
</property>
<property name="receiptDate" type="java.util.Date">
<column name="receipt_date" not-null="true">
<comment></comment>
</column>
</property>
<property name="remarks" type="java.lang.String">
<column name="remarks">
<comment></comment>
</column>
</property>
<!--<property name="status" type="java.lang.Character">-->
<!--<column name="status" length="1" not-null="true">-->
<!--<comment></comment>-->
<!--</column>-->
<!--</property>-->
<!--<property name="approvedOn" type="java.util.Date">-->
<!--<column name="approved_on" length="19">-->
<!--<comment></comment>-->
<!--</column>-->
<!--</property>-->
<!---->
<!--<property name="approvedBy" type="java.lang.Integer">-->
<!--<column name="approved_by" length="10">-->
<!--<comment></comment>-->
<!--</column>-->
<!--</property>-->

<property name="createdBy" type="java.lang.Integer">
<column name="created_by" not-null="true">
<comment></comment>
</column>
</property>
<property name="createdOn" type="java.util.Date">
<column name="created_on" length="19" not-null="true">
<comment></comment>
</column>
</property>
<property name="modifiedBy" type="java.lang.Integer">
<column name="modified_by">
<comment></comment>
</column>
</property>
<property name="modifiedOn" type="java.util.Date">
<column name="modified_on" length="19">
<comment></comment>
</column>
</property>
<property name="deleted" type="java.lang.Byte">
<column name="deleted" not-null="true">
<comment></comment>
</column>
</property>
<property name="location" type="java.lang.Integer">
<column name="location" not-null="true">
<comment></comment>
</column>
</property>

<property name="actionBy" type="java.lang.Integer">
<column name="action_by" >
<comment></comment>
</column>
</property>

<property name="actionOn" type="java.util.Date">
<column name="action_on" >
<comment></comment>
</column>
</property>

<property name="action" type="java.lang.Character">
<column name="action">
<comment></comment>
</column>
</property>
</class>
</hibernate-mapping>

************************************************************
SQL for receipt_voucher table:
CREATE TABLE `receipt_voucher` (
`id` bigint(20) unsigned NOT NULL default '0',
`receipt_no` varchar(10) NOT NULL default '',
`receipt_date` date NOT NULL default '0000-00-00',
`ar_transaction_type_id` int(10) unsigned NOT NULL default '0',
`customer_id` int(10) unsigned NOT NULL default '0',
`receipt_mode` char(1) NOT NULL default '',
`coa_id` int(10) unsigned NOT NULL default '0',
`advance_receipt_id` bigint(20) unsigned default NULL,
`bank_name` varchar(50) default NULL,
`cheque_no` varchar(15) default NULL,
`cheque_date` date default NULL,
`inter_company` tinyint(1) NOT NULL default '0',
`late_charges` double default NULL,
`amount` double NOT NULL default '0',
`remarks` varchar(255) default NULL,
`employee_id` int(10) unsigned default NULL,
`recovery_receipt_no` varchar(10) default NULL,
`created_by` int(10) unsigned NOT NULL default '0',
`created_on` datetime NOT NULL default '0000-00-00 00:00:00',
`modified_by` int(10) unsigned default NULL,
`modified_on` datetime default NULL,
`deleted` tinyint(1) NOT NULL default '0',
`location` int(10) unsigned NOT NULL default '0',
`action` char(1) default NULL,
`action_by` int(10) unsigned default NULL,
`action_on` datetime default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ix_receipt_voucher_receipt_no` (`receipt_no`),
KEY `ix_receipt_voucher_customer` (`customer_id`),
KEY `ix_receipt_voucher_ar_transaction_type` (`ar_transaction_type_id`),
KEY `ix_receipt_voucher_coa` (`coa_id`),
KEY `ix_receipt_voucher_advance_receipt` (`advance_receipt_id`),
KEY `ix_receipt_voucher_employee` (`employee_id`),
KEY `ix_receipt_voucher_action_by` (`action_by`),
CONSTRAINT `fk_receipt_voucher_advance_receipt` FOREIGN KEY (`advance_receipt_id`) REFERENCES `advance_receipt` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_receipt_voucher_ar_transaction_type` FOREIGN KEY (`ar_transaction_type_id`) REFERENCES `ar_transaction_type` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_receipt_voucher_coa` FOREIGN KEY (`coa_id`) REFERENCES `coa` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_receipt_voucher_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_receipt_voucher_employee` FOREIGN KEY (`employee_id`) REFERENCES `employee` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
************************************************************
*************************************************************
AdvanceReceipt:
*************************************************************
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jul 25, 2006 6:26:33 PM by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
<class name="com.tsd.model.entitybean.ar.AdvanceReceipt" table="advance_receipt" >
<comment></comment>
<id name="id" type="java.lang.Long">
<column name="id" />
<generator class="assigned" />
</id>

<many-to-one name="coa" class="com.tsd.model.entitybean.ar.ARCoa" fetch="join">
<column name="coa_id" not-null="true">
<comment></comment>
</column>
</many-to-one>
<many-to-one name="reversalReason" class="com.tsd.model.entitybean.ar.ReversalReason" fetch="join">
<column name="reversal_reason_id">
<comment></comment>
</column>
</many-to-one>
<many-to-one name="customer" class="com.tsd.model.entitybean.ar.ARCustomer" fetch="join">
<column name="customer_id" not-null="true">
<comment></comment>
</column>
</many-to-one>
<!-- <many-to-one name="arCostCenter" class="com.tsd.model.entitybean.ar.ARCostCenter" fetch="join">
<column name="costcenter_id" not-null="true">
<comment></comment>
</column>
</many-to-one>-->
<many-to-one name="employeeByReceivedBy" class="com.tsd.model.entitybean.ar.AREmployee" fetch="join">
<column name="received_by" not-null="true">
<comment></comment>
</column>
</many-to-one>
<many-to-one name="arTransactionType" class="com.tsd.model.entitybean.ar.ArTransactionType" fetch="join">
<column name="ar_transaction_type_id" not-null="true">
<comment></comment>
</column>
</many-to-one>
<property name="receiptNo" type="java.lang.String">
<column name="receipt_no" length="10" not-null="true">
<comment></comment>
</column>
</property>
<property name="bankName" type="java.lang.String">
<column name="bank_name" length="50">
<comment></comment>
</column>
</property>
<property name="receiptDate" type="java.util.Date">
<column name="receipt_date" not-null="true">
<comment></comment>
</column>
</property>
<property name="receiptMode" type="java.lang.Character">
<column name="receipt_mode" length="1" not-null="true">
<comment></comment>
</column>
</property>
<property name="chequeNo" type="java.lang.String">
<column name="cheque_no" length="10">
<comment></comment>
</column>
</property>
<property name="chequeDate" type="java.util.Date">
<column name="cheque_date">
<comment></comment>
</column>
</property>
<property name="amount" type="java.lang.Double">
<column name="amount" precision="22" scale="0" not-null="true">
<comment></comment>
</column>
</property>
<property name="remarks" type="java.lang.String">
<column name="remarks">
<comment></comment>
</column>
</property>
<property name="status" type="java.lang.Character">
<column name="status" length="1" not-null="true">
<comment></comment>
</column>
</property>
<property name="reversalOn" type="java.util.Date">
<column name="reversal_on" >
<comment></comment>
</column>
</property>
<property name="reversalBy" type="java.lang.Integer">
<column name="reversal_by">
<comment></comment>
</column>
</property>
<property name="action" type="java.lang.Character">
<column name="action" length="1" not-null="true">
<comment></comment>
</column>
</property>
<property name="actionOn" type="java.util.Date">
<column name="action_on" length="19">
<comment></comment>
</column>
</property>
<property name="actionBy" type="java.lang.Integer">
<column name="action_by">
<comment></comment>
</column>
</property>
<property name="createdBy" type="java.lang.Integer">
<column name="created_by" not-null="true">
<comment></comment>
</column>
</property>
<property name="createdOn" type="java.util.Date">
<column name="created_on" not-null="true">
<comment></comment>
</column>
</property>
<property name="modifiedBy" type="java.lang.Integer">
<column name="modified_by">
<comment></comment>
</column>
</property>
<property name="modifiedOn" type="java.util.Date">
<column name="modified_on">
<comment></comment>
</column>
</property>
<property name="deleted" type="java.lang.Byte">
<column name="deleted" not-null="true">
<comment></comment>
</column>
</property>
<property name="location" type="java.lang.Integer">
<column name="location" not-null="true">
<comment></comment>
</column>
</property>
</class>
</hibernate-mapping>

************************************************************
SQL for advance_receipt
************************************************************
CREATE TABLE `advance_receipt` (
`id` bigint(20) unsigned NOT NULL default '0',
`receipt_no` varchar(10) NOT NULL default '',
`receipt_date` date NOT NULL default '0000-00-00',
`customer_id` int(10) unsigned NOT NULL default '0',
`receipt_mode` char(1) NOT NULL default '',
`coa_id` int(10) unsigned NOT NULL default '0',
`cheque_no` varchar(15) default NULL,
`amount` double NOT NULL default '0',
`remarks` varchar(255) default NULL,
`status` char(1) NOT NULL default '',
`received_by` int(10) unsigned NOT NULL default '0',
`reversal_by` int(10) unsigned default NULL,
`reversal_on` datetime default NULL,
`reversal_reason_id` int(10) unsigned default NULL,
`created_by` int(10) unsigned NOT NULL default '0',
`created_on` datetime NOT NULL default '0000-00-00 00:00:00',
`modified_by` int(10) unsigned default NULL,
`modified_on` datetime default NULL,
`deleted` tinyint(1) NOT NULL default '0',
`location` int(10) unsigned NOT NULL default '0',
`ar_transaction_type_id` int(10) unsigned NOT NULL default '0',
`bank_name` varchar(50) default NULL,
`cheque_date` date default NULL,
`action` char(1) default NULL,
`action_by` int(10) unsigned default NULL,
`action_on` datetime default NULL,
PRIMARY KEY (`id`),
KEY `ix_advance_receipt_customer` (`customer_id`),
KEY `ix_advance_receipt_coa` (`coa_id`),
KEY `ix_advance_receipt_received_by` (`received_by`),
KEY `ix_advance_receipt_reversal_by` (`reversal_by`),
KEY `ix_advance_receipt_reversal_reason` (`reversal_reason_id`),
KEY `ix_advance_receipt_ar_transaction_type` (`ar_transaction_type_id`),
KEY `ix_advance_receipt_action_by` (`action_by`),
CONSTRAINT `advance_receipt_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `advance_receipt_ibfk_2` FOREIGN KEY (`coa_id`) REFERENCES `coa` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `advance_receipt_ibfk_3` FOREIGN KEY (`received_by`) REFERENCES `employee` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `advance_receipt_ibfk_4` FOREIGN KEY (`reversal_by`) REFERENCES `employee` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `advance_receipt_ibfk_5` FOREIGN KEY (`reversal_reason_id`) REFERENCES `reversal_reason` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_advance_receipt_ar_transaction_type` FOREIGN KEY (`ar_transaction_type_id`) REFERENCES `ar_transaction_type` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


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.