-->
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.  [ 4 posts ] 
Author Message
 Post subject: NULL objects in collection
PostPosted: Mon May 08, 2006 12:08 pm 
Newbie

Joined: Thu Feb 19, 2004 10:25 pm
Posts: 16
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.1.2

Mapping documents:
<?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 Apr 15, 2006 8:36:44 PM by Hibernate Tools 3.1.0.beta4 -->
<hibernate-mapping>
<class name="org.ridoc.orm.NamesInmateView" table="NAMES_INMATE_VIEW" schema="DBARI">
<composite-id name="id" class="org.ridoc.orm.NamesInmateViewId">
<key-property name="NLastName" type="string">
<column name="N_LAST_NAME" length="18" />
</key-property>
<key-property name="NFirstName" type="string">
<column name="N_FIRST_NAME" length="15" />
</key-property>
<key-property name="NMinit" type="string">
<column name="N_MINIT" length="1" />
</key-property>
<key-property name="NInmateId" type="integer">
<column name="N_INMATE_ID" precision="7" scale="0" />
</key-property>
<key-property name="NDob" type="date">
<column name="N_DOB" length="7" />
</key-property>
<key-property name="NSsno" type="string">
<column name="N_SSNO" length="9" />
</key-property>
<key-property name="NAka" type="string">
<column name="N_AKA" length="1" />
</key-property>
<key-property name="NSuffix" type="string">
<column name="N_SUFFIX" length="4" />
</key-property>
<key-property name="NStatus" type="string">
<column name="N_STATUS" length="2" />
</key-property>
<key-property name="NIncarcerationNumber" type="java.lang.Integer">
<column name="N_INCARCERATION_NUMBER" precision="7" scale="0" />
</key-property>
<key-property name="ISecurityId" type="string">
<column name="I_SECURITY_ID" length="3" />
</key-property>
<key-property name="IArea" type="string">
<column name="I_AREA" length="8" />
</key-property>
<key-property name="ICellId" type="string">
<column name="I_CELL_ID" length="6" />
</key-property>
<key-property name="IDob" type="date">
<column name="I_DOB" length="7" />
</key-property>
<key-property name="IRace" type="string">
<column name="I_RACE" length="2" />
</key-property>
<key-property name="ISex" type="string">
<column name="I_SEX" length="1" />
</key-property>
<key-property name="IStatus" type="string">
<column name="I_STATUS" length="2" />
</key-property>
<key-property name="IClassCode" type="string">
<column name="I_CLASS_CODE" length="3" />
</key-property>
<key-property name="IPcIndicator" type="string">
<column name="I_PC_INDICATOR" length="1" />
</key-property>
<key-property name="ILastName" type="string">
<column name="I_LAST_NAME" length="18" />
</key-property>
<key-property name="IFirstName" type="string">
<column name="I_FIRST_NAME" length="15" />
</key-property>
<key-property name="IMinit" type="string">
<column name="I_MINIT" length="1" />
</key-property>
<key-property name="ISuffix" type="string">
<column name="I_SUFFIX" length="4" />
</key-property>
<key-property name="IHwobFlag" type="java.lang.Short">
<column name="I_HWOB_FLAG" precision="3" scale="0" />
</key-property>
<key-property name="ICountNames" type="java.lang.Short">
<column name="I_COUNT_NAMES" precision="3" scale="0" />
</key-property>
<key-property name="ILimitCount" type="java.lang.Short">
<column name="I_LIMIT_COUNT" precision="3" scale="0" />
</key-property>
<key-property name="IEnemies" type="java.lang.Short">
<column name="I_ENEMIES" precision="3" scale="0" />
</key-property>
<key-property name="IEnemiesOf" type="java.lang.Short">
<column name="I_ENEMIES_OF" precision="3" scale="0" />
</key-property>
<key-property name="ITotEnemies" type="java.lang.Short">
<column name="I_TOT_ENEMIES" precision="3" scale="0" />
</key-property>
<key-property name="IFpNbr2" type="string">
<column name="I_FP_NBR2" length="10" />
</key-property>
<key-property name="IFpClass1" type="java.lang.Short">
<column name="I_FP_CLASS1" precision="3" scale="0" />
</key-property>
<key-property name="IFpClass2" type="java.lang.Short">
<column name="I_FP_CLASS2" precision="3" scale="0" />
</key-property>
<key-property name="ISmoker" type="string">
<column name="I_SMOKER" length="1" />
</key-property>
<key-property name="IResideWithSmoker" type="string">
<column name="I_RESIDE_WITH_SMOKER" length="1" />
</key-property>
<key-property name="IDatePhotoTaken" type="date">
<column name="I_DATE_PHOTO_TAKEN" length="7" />
</key-property>
<key-property name="ISosCode" type="string">
<column name="I_SOS_CODE" length="2" />
</key-property>
<key-property name="ISosLocation" type="string">
<column name="I_SOS_LOCATION" length="20" />
</key-property>
<key-property name="ISosState" type="string">
<column name="I_SOS_STATE" length="2" />
</key-property>
<key-property name="ISrg" type="string">
<column name="I_SRG" length="1" />
</key-property>
<key-property name="IBinNumber" type="string">
<column name="I_BIN_NUMBER" length="4" />
</key-property>
<key-property name="IIncarcerationNumber" type="java.lang.Integer">
<column name="I_INCARCERATION_NUMBER" precision="7" scale="0" />
</key-property>
<key-property name="VNameField" type="string">
<column name="V_NAME_FIELD" length="25" />
</key-property>
<key-property name="VAliasMesg" type="string">
<column name="V_ALIAS_MESG" length="3" />
</key-property>
<key-property name="VSmoker" type="string">
<column name="V_SMOKER" length="1" />
</key-property>
<key-property name="VBillable" type="string">
<column name="V_BILLABLE" length="28" />
</key-property>
<key-property name="VSrg" type="string">
<column name="V_SRG" length="3" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Using Spring to open and close the session.

Full stack trace of any exception that occurs:

Name and version of the database you are using:
Oracle 9i


The generated SQL (show_sql=true):
Hibernate: select namesinmat0_.N_LAST_NAME as N1_204_, namesinmat0_.N_FIRST_NAME as N2_204_, namesinmat0_.N_MINIT as N3_204_, namesinmat0_.N_INMATE_ID as N4_204_, namesinmat0_.N_DOB as N5_204_, namesinmat0_.N_SSNO as N6_204_, namesinmat0_.N_AKA as N7_204_, namesinmat0_.N_SUFFIX as N8_204_, namesinmat0_.N_STATUS as N9_204_, namesinmat0_.N_INCARCERATION_NUMBER as N10_204_, namesinmat0_.I_SECURITY_ID as I11_204_, namesinmat0_.I_AREA as I12_204_, namesinmat0_.I_CELL_ID as I13_204_, namesinmat0_.I_DOB as I14_204_, namesinmat0_.I_RACE as I15_204_, namesinmat0_.I_SEX as I16_204_, namesinmat0_.I_STATUS as I17_204_, namesinmat0_.I_CLASS_CODE as I18_204_, namesinmat0_.I_PC_INDICATOR as I19_204_, namesinmat0_.I_LAST_NAME as I20_204_, namesinmat0_.I_FIRST_NAME as I21_204_, namesinmat0_.I_MINIT as I22_204_, namesinmat0_.I_SUFFIX as I23_204_, namesinmat0_.I_HWOB_FLAG as I24_204_, namesinmat0_.I_COUNT_NAMES as I25_204_, namesinmat0_.I_LIMIT_COUNT as I26_204_, namesinmat0_.I_ENEMIES as I27_204_, namesinmat0_.I_ENEMIES_OF as I28_204_, namesinmat0_.I_TOT_ENEMIES as I29_204_, namesinmat0_.I_FP_NBR2 as I30_204_, namesinmat0_.I_FP_CLASS1 as I31_204_, namesinmat0_.I_FP_CLASS2 as I32_204_, namesinmat0_.I_SMOKER as I33_204_, namesinmat0_.I_RESIDE_WITH_SMOKER as I34_204_, namesinmat0_.I_DATE_PHOTO_TAKEN as I35_204_, namesinmat0_.I_SOS_CODE as I36_204_, namesinmat0_.I_SOS_LOCATION as I37_204_, namesinmat0_.I_SOS_STATE as I38_204_, namesinmat0_.I_SRG as I39_204_, namesinmat0_.I_BIN_NUMBER as I40_204_, namesinmat0_.I_INCARCERATION_NUMBER as I41_204_, namesinmat0_.V_NAME_FIELD as V42_204_, namesinmat0_.V_ALIAS_MESG as V43_204_, namesinmat0_.V_SMOKER as V44_204_, namesinmat0_.V_BILLABLE as V45_204_, namesinmat0_.V_SRG as V46_204_ from DBARI.NAMES_INMATE_VIEW namesinmat0_ where namesinmat0_.N_INMATE_ID>91105 and namesinmat0_.N_INMATE_ID<95999


Debug level Hibernate log excerpt:
????

OK, I used Hibernate tools to gen. my maps. In this case I'm trying to query a view that has two tables in it. What is happening is that it is bringing back a list object. That object looks like it has the correct number of items in it but, all the objects are null!!! At first I thought this had something to do with lazy loading. Therefore I took a number of steps to fix that issue including just setting lazy="false" on all mapping files involved, wrapping the query in a transaction and using the OpenSessionInViewInterceptor AOP interceptor all of which did not work.

The other thing I noticed is that I used Hibernate Tools to gen the maps and it seems that on all the view objects in the database it put all the field of the views into compound keys. I'm not sure why it did this but I'm not planning to doing any data updateing through the views anyway so I don't much care unless this is the cause of my problem.

Has anyone run into this before or could someone offer me some advice on how to correct the problem?

TIA,

-ScottTavares-

_________________
-Scott-


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 11:41 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The problem must be with however you caused that mapping to be generated. That is not a good mapping. All the columns are in the database key, leaving no columns available for a business key, meaning that hashCode and equals will never work. The problem with all-null results is very likely something to do with a badly-written hashCode method, but since there is no "good" hashCode method possible for this mapping, I don't think that there's a solution.

I recommend abandoning the generated mapping, and rewrite it manually.

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 1:49 pm 
Newbie

Joined: Mon Mar 20, 2006 1:16 pm
Posts: 5
I have exactly the same situation but this response has me confused. From the FAQs "How can I map a table (or view) with no primary key?

Every table (or even view) should have some unique key. The mathematical definition of a relation is a set of tuples. (Sets do not permit duplicate elements.) Furthermore, truly identical rows can not possibly have any meaningful semantics from the user's perspective.

In some cases it may be sensible to go as far as mapping all columns of a view as a <composite-id/>, but there is almost always some smaller business key. (Note that Hibernate does not require that this unique key be enforced by the database schema, of course.)"


That certainly leaves the impression that this kind of mapping is contemplated.

A few other observations from my investigation.
I am doing a simple "from myView" query to return all rows. Debugging shows all rows are returned and that default constructors for the myView as well as the myViewId class are called and myView.setId is called as well, once each for every row returned. At no time are the equals() or hashCode() methods of either myView or myViewId called. I get back an ArrayList of 130 objects that are all null.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 2:17 pm 
Newbie

Joined: Mon Mar 20, 2006 1:16 pm
Posts: 5
I found my culprit. One of the columns in the view is nullable and was null. Obviously, null columns and primary keys don't mix. I moved that column out of the composite-id mapping, made corresponding changes to the java and the query works fine.


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