-->
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.  [ 10 posts ] 
Author Message
 Post subject: Exception when retrieving some records frustating problem...
PostPosted: Sat Nov 20, 2004 3:07 am 
Newbie

Joined: Wed May 12, 2004 7:59 am
Posts: 7
Hi all,
Please look at the following details and help, unable to find a reason why the query fails!!! It works for some records and for some recrods it throws up this exception.


Sarath.
PS: I posted this yesterday but did not get any response, i need some help urgently so am reposting it.

Hibernate version: Hibernate2

Mapping documents:Issue and IssueDetails (one to many relationship)
Issue has Issue_id, date, and other header information, IssueDetails has IssueDetailId, IssueId (link to parent object), and other order details.

Code between sessionFactory.openSession()
....
session.find ("from Issue where issue_date = '2004-11-02'");
....
and session.close():

Full stack trace of any exception that occurs:
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(String.java:460)
at net.sf.hibernate.type.CharacterType.get(CharacterType.java:23)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:62)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:53)
at net.sf.hibernate.type.AbstractType.hydrate(AbstractType.java:66)
at net.sf.hibernate.loader.Loader.hydrate(Loader.java:611)
at net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:552)
at net.sf.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:511)
at net.sf.hibernate.loader.Loader.getRow(Loader.java:426)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:209)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:955)
at net.sf.hibernate.loader.Loader.list(Loader.java:946)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:846)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1543)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1520)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1512)
at com.quadone.hms.inventory.storagehandlers.IssueSH.findByDate(IssueSH.java:366)
at com.quadone.hms.inventory.storagehandlers.testers.IssuesFindByDateTester.testFindByDate(IssuesFindByDateTester.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:410)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:294)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:182)
java.lang.NullPointerException
null
at com.quadone.hms.inventory.storagehandlers.testers.IssuesFindByDateTester.testFindByDate(IssuesFindByDateTester.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:410)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:294)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:182)


Name and version of the database you are using:
MySql 4.0.20

The generated SQL (show_sql=true):
select issuebo0_.issue_id as issue_id, issuebo0_.indent_id as indent_id, issuebo0_.issue_type as issue_type, issuebo0_.patient_code as patient_4_, issuebo0_.patient_name as patient_5_, issuebo0_.is_credit as is_credit, issuebo0_.age as age, issuebo0_.address as address, issuebo0_.referral_doctor as referral9_, issuebo0_.issue_date as issue_date, issuebo0_.total_amount as total_a11_, issuebo0_.discount_type as discoun12_, issuebo0_.discount_amount as discoun13_, issuebo0_.tax as tax, issuebo0_.net_amount as net_amount, issuebo0_.from_stock_point_id as from_st16_, issuebo0_.to_stock_point_id as to_stoc17_, issuebo0_.remarks as remarks, issuebo0_.is_completed_issued as is_comp19_, issuebo0_.is_active as is_active from inv_issue_header issuebo0_ where (issue_date='2004-11-02' )

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 21, 2004 3:00 pm 
Regular
Regular

Joined: Tue Jan 27, 2004 12:22 pm
Posts: 103
Help us to help you, please fill out the required information. I'll quess that the problem is in the date string you provided in the query. This is database dependent. Use named parameters in your query. Something like:
Code:
session.createQuery("...where issuedate=:date").setCalendar("date",Calendar.getInstance()).list();

Greetz

_________________
Dencel
- The sun has never seen a shadow -


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 21, 2004 3:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you don't show the mapping so we can't help much, except looking in hibernate2 src code (which you can to :)

In here you'll see that Hibernate is trying to access str.charAt(0) on a result which is non-null on something that has been mapped as a Character(1) - thus either you data is not as expected or the mapping is wrong.

The reason why it only happens once in a while is because some records has this error and some others don't.

If you don't have an idea on what column this is occuring for then the easist is to set a breakpoint and step in there with a debugger to see the name of the column failing.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 22, 2004 12:42 am 
Newbie

Joined: Wed May 12, 2004 7:59 am
Posts: 7
Hi Max,
Thanks for your reply. I am attaching the mapping file. there is no issue with them mapping files it is a simple master detail (one to many) relationship. But i will still put it in this post.


Because it was happenning with only a few records, it obviously was a problem with the data but i was not able to understand which data was missing. Thanks for your point towards the char(1) field. I will check up and get back to you.

Can you explain the process in which records are being fetched and the flow or direct me to some documentation of how the record is built.
I missed that understanding and was not clear where the problem was occurring.


Sarath.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 22, 2004 12:56 am 
Newbie

Joined: Wed May 12, 2004 7:59 am
Posts: 7
Dencel wrote:
Help us to help you, please fill out the required information. I'll quess that the problem is in the date string you provided in the query. This is database dependent. Use named parameters in your query. Something like:
Code:
session.createQuery("...where issuedate=:date").setCalendar("date",Calendar.getInstance()).list();

Greetz


Hi Dencel,
Thanks for your response. I am using mySql DB for the query and it is working fine for most of the records but failing for only a few. Like max suggested in the the next mail, i am checking the data in the DB for any non null char(1) column to see if it has a null value.

Sarath.

PS: I am attaching the mapping files.
IssueBO
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="com.quadone.hms.inventory.businessobjects.IssueBO" table="inv_issue_header">
<id name="issueId" column="issue_id" type="long">
<generator class="increment"/>
</id>

<many-to-one class="com.quadone.hms.inventory.businessobjects.IndentBO" name="indentId" column="indent_id"/>
<property name="issueType" column="issue_type" type="string" length="5" not-null="true"/>
<property name="patientCode" column="patient_code" type="long"/>
<property name="patientName" column="patient_name" unique="true" length="60" type="string"/>
<property name="isCredit" column="is_credit" type="boolean"/>
<property name="age" column="age" type="float"/>
<property name="address" column="address" type="string" length="255" unique="true"/>
<property name="referralDoctor" column="referral_doctor" length="60" type="string"/>
<property name="issueDate" column="issue_date" type="date" not-null="true"/>
<!-- we have to add amount information and we have to remove remarks field in issueitembo mapping file -->

<property name="totalAmount" column="total_amount" type="float" not-null="true"/>
<property name="discountType" column="discount_type" type="string"/>
<property name="discountAmount" column="discount_amount" type="float"/>
<property name="tax" column="tax" type="float"/>
<property name="netAmount" column="net_amount" type="float" not-null="true"/>

<many-to-one class="com.quadone.hms.inventory.businessobjects.StockPointBO" name="fromStockPoint" column="from_stock_point_id"/>

<many-to-one class="com.quadone.hms.inventory.businessobjects.StockPointBO" name="toStockPoint" column="to_stock_point_id" not-null="true"/>
<set name="issueItems" cascade="all" order-by="issue_item_id asc">
<key column="issue_id"/>
<one-to-many class="com.quadone.hms.inventory.businessobjects.IssueItemBO"/>
</set>

<property name="remarks" column="remarks" type="string" length="255"/>

<property name="isCompletedIssue" column="is_completed_issued" type="char"/>
<property name="isActive" column="is_active" type="boolean"/>

</class>
</hibernate-mapping>

--------------------------------

IssueItemBO
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="com.quadone.hms.inventory.businessobjects.IssueItemBO" table="inv_issue_item">
<id name="issueItemId" column="issue_item_id" type="long">
<generator class="increment"/>
</id>

<many-to-one class="com.quadone.hms.inventory.businessobjects.IssueBO" name="issueId" column="issue_id"/>
<many-to-one class="com.quadone.hms.inventory.businessobjects.MaterialBO" name="mtrlId" column="mtrl_id"/>
<many-to-one class="com.quadone.hms.general.businessobjects.UomBO" name="uomId" column="uom_id"/>
<many-to-one class="com.quadone.hms.inventory.businessobjects.BatchBO" name="batchId" column="batch_id"/>
<property name="qty" column="qty" type="float"/>
<property name="issueprice" column="issueprice" type="float" not-null='true'/>
<property name="costtype" column="costtype" type="string"/>

<!-- <property name="remarks" column="remarks" type="string" length="255"/> -->
<property name="isIssued" column="is_issued" type="char"/>
<property name="isActive" column="is_active" type="boolean"/>

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: mysql tables associated with the mapping files ...
PostPosted: Mon Nov 22, 2004 1:07 am 
Newbie

Joined: Wed May 12, 2004 7:59 am
Posts: 7
Hi,
I am attaching a description of the tables associated with the above mapping files in this post. Please review and indicate the probable areas that i should check up on.

I checked for any char(1) field that is defined as non null with null data!!! There are none like that in the DB.

mysql> desc inv_issue_header;
+---------------------+--------------+------+-----+------------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+--------------+------+-----+------------+-------+
| issue_id | bigint(20) | | PRI | 0 | |
| indent_id | bigint(20) | YES | MUL | NULL | |
| issue_type | varchar(5) | YES | | NULL | |
| patient_code | bigint(20) | YES | | NULL | |
| patient_name | varchar(60) | YES | | NULL | |
| age | float | YES | | NULL | |
| address | varchar(255) | YES | | NULL | |
| referral_doctor | varchar(60) | YES | | NULL | |
| issue_date | date | | | 0000-00-00 | |
| total_amount | float | | | 0 | |
| discount_type | varchar(255) | YES | | NULL | |
| discount_amount | float | YES | | NULL | |
| tax | float | YES | | NULL | |
| net_amount | float | | | 0 | |
| from_stock_point_id | bigint(20) | YES | MUL | NULL | |
| to_stock_point_id | bigint(20) | | MUL | 0 | |
| remarks | varchar(255) | YES | | NULL | |
| is_completed_issued | char(1) | YES | | NULL | |
| is_active | tinyint(1) | YES | | NULL | |
| is_credit | tinyint(1) | | | 0 | |
+---------------------+--------------+------+-----+------------+-------+


mysql> desc inv_issue_item;
+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| issue_item_id | bigint(20) | | PRI | 0 | |
| issue_id | bigint(20) | YES | MUL | NULL | |
| mtrl_id | bigint(20) | YES | MUL | NULL | |
| uom_id | bigint(20) | YES | MUL | NULL | |
| batch_id | bigint(20) | YES | MUL | NULL | |
| qty | float | YES | | NULL | |
| is_issued | char(1) | YES | | NULL | |
| is_active | tinyint(1) | YES | | NULL | |
| costtype | varchar(20) | YES | | NULL | |
| issueprice | float | | | 0 | |
+---------------+-------------+------+-----+---------+-------+


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 22, 2004 4:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
kcsarath wrote:
Can you explain the process in which records are being fetched and the flow or direct me to some documentation of how the record is built.
I missed that understanding and was not clear where the problem was occurring.


The stacktrace you provided shows very precisely where and how the objects are built (hydrated) from a resultset via Type's.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: mysql tables associated with the mapping files ...
PostPosted: Mon Nov 22, 2004 4:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
kcsarath wrote:
I checked for any char(1) field that is defined as non null with null data!!! There are none like that in the DB.


I didn't say it was null - I said it was non-null and str.charAt(0) was causing the error. This probably means that the string is empty, but non null!

And looking at your mapping and schemas the cause is probably in your is_active field.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 22, 2004 5:54 am 
Newbie

Joined: Wed May 12, 2004 7:59 am
Posts: 7
hi max,
I understand that the StringIndexOutOfBounds is happenning because String.charAt(0) is causing the problem.

But what i want to know is under what circumstances does this kind of thing happen.

The records associated with the problem have all the fields same as the records that are not causing the problem.!!!

is_active has the same value for a record that is causing the problem and another record which is not causing the problem.


Thanks for your time, Please do help, if there is any thing specific that I can provide for you to get a better idea please tell me.

Sarath.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 22, 2004 5:59 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
it happens when that column is an empty string '' instead of a 1 char length field 'X'

_________________
Max
Don't forget to rate


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