-->
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: Spaces to be treated as NULL
PostPosted: Tue Oct 19, 2004 2:14 pm 
Newbie

Joined: Tue Oct 19, 2004 12:18 pm
Posts: 4
Description: We are forced to use a legacy DB2400 database where each and every field is defined as 'NOT NULLABLE'. This is the case even for those fields storing foreign keys to other entities. In fact for these cases a series of spaces is stored(to represent no association) instead of a NULL value. Refer to highlighted section within the attached log file snippet(shows VHPROJ and VHELNO fields containing spaces as part of lookup operation). Because of this the attached excpetion is being thrown at the point Hibernate is attempting to build the object graph . In this case it was for a one-to-many relationship. Everything works great( ie the entire object graph is retrieved) if valid values exists within the VHPROJ and VHELNO columns of the MWOHED(ManufacturingOrder) table.

Any suggestions on what could/should be done to work around this problem. Is there a attribute/element within the mapping files which could be added at the point of defining the one-to-many relationship? One-to-on relationship? Many-to-Many relationship? Should we define a PropertyAccessor to handle such a scenerio? Do we need to alter the DB2400Dialect class?

As you can tell I am open to any suggestions.

[b]Hibernate version:
2.1.6, 9.8.2004

Mapping documents:
ManufacturingOrder has a one-to-many relationship with Projects. Defined as follows(Pulled the interesting sections from each of the mapping files).

ManufacturingOrder.hbm
<hibernate-mapping package="com.htch.erp.hibernate.movex">
<class name="ManufacturingOrder" table="MWOHED">
<composite-id name="id" class="com.htch.erp.hibernate.movex.ManufacturingOrderCompositeID">
<key-property name="companyNumber" column="VHCONO" type="integer" />
<key-property name="itemNumber" column="VHITNO" type="string" />
<key-property name="orderNumber" column="VHMFNO" type="integer" />
</composite-id>
<!-- Project -->
<many-to-one name="project"
class="com.htch.erp.hibernate.movex.Projects"
insert="false"
update="false"
not-null="false">
<column name="VHCONO"/>
<column name="VHPROJ"/>
<column name="VHELNO"/>
</many-to-one>
</class>
</hibernate-mapping>

Projects.hbm
<hibernate-mapping package="com.htch.erp.hibernate.movex">
<class name="Projects" table="BPROJS">
<composite-id name="id" class="com.htch.erp.hibernate.movex.ProjectsCompositeID" >
<key-property name="companyNumber" column="LACONO" type="integer" />
<key-property name="projectsNumber" column="LAPROJ" type="string" />
<key-property name="elementNumber" column="LAELNO" type="string" />
</composite-id>
<!-- Manufacturing Orders -->
<set name="manufacturingOrders" lazy="true" inverse="false">
<key>
<column name="VHCONO"/>
<column name="VHPROJ"/>
<column name="VHELNO"/>
</key>
<one-to-many class="com.htch.erp.hibernate.movex.ManufacturingOrder"/>
</set>

</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs: net.sf.hibernate.UnresolvableObjectException: No row with the given identifier exists: com.htch.erp.hibernate.movex.ProjectsCompositeID@8d370a75, of class: com.htch.erp.hibernate.movex.Projects
at net.sf.hibernate.UnresolvableObjectException.throwIfNull(UnresolvableObjectException.java:38)
at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1954)
at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:69)
at net.sf.hibernate.type.EntityType.resolveIdentifier(EntityType.java:204)
at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2206)
at net.sf.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:315)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:305)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at net.sf.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:550)
at com.htch.erp.hibernate.movextests.MOTest.testGetMOItemTest(MOTest.java:70)
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:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)



Name and version of the database you are using: DB2400 version

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt: debug
[DEBUG] 19 Oct 10:50:23.803 AM main [net.sf.hibernate.persister.EntityPersister] Materializing entity: [com.htch.erp.hibernate.movex.Projects#com.htch.erp.hibernate.movex.ProjectsCompositeID@8d370a75]
[DEBUG] 19 Oct 10:50:23.803 AM main [net.sf.hibernate.impl.BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
[DEBUG] 19 Oct 10:50:23.803 AM main [net.sf.hibernate.SQL] select projects0_.LACONO as LACONO0_, projects0_.LAPROJ as LAPROJ0_, projects0_.LAELNO as LAELNO0_, projects0_.LASTAT as LASTAT0_, projects0_.LATX40 as LATX400_, projects0_.LATX15 as LATX150_, projects0_.LAATYP as LAATYP0_, projects0_.LASPLE as LASPLE0_, projects0_.LAFRE5 as LAFRE50_ from BPROJS projects0_ where projects0_.LACONO=? and projects0_.LAPROJ=? and projects0_.LAELNO=?
Hibernate: select projects0_.LACONO as LACONO0_, projects0_.LAPROJ as LAPROJ0_, projects0_.LAELNO as LAELNO0_, projects0_.LASTAT as LASTAT0_, projects0_.LATX40 as LATX400_, projects0_.LATX15 as LATX150_, projects0_.LAATYP as LAATYP0_, projects0_.LASPLE as LASPLE0_, projects0_.LAFRE5 as LAFRE50_ from BPROJS projects0_ where projects0_.LACONO=? and projects0_.LAPROJ=? and projects0_.LAELNO=?
[DEBUG] 19 Oct 10:50:23.803 AM main [net.sf.hibernate.impl.BatcherImpl] preparing statement
[DEBUG] 19 Oct 10:50:23.903 AM main [net.sf.hibernate.type.IntegerType] binding '1' to parameter: 1
[DEBUG] 19 Oct 10:50:23.903 AM main [net.sf.hibernate.type.StringType] binding ' ' to parameter: 2
[DEBUG] 19 Oct 10:50:23.903 AM main [net.sf.hibernate.type.StringType] binding ' ' to parameter: 3

[DEBUG] 19 Oct 10:50:23.943 AM main [net.sf.hibernate.loader.Loader] processing result set
[DEBUG] 19 Oct 10:50:23.943 AM main [net.sf.hibernate.loader.Loader] done processing result set (0 rows)
[DEBUG] 19 Oct 10:50:23.943 AM main [net.sf.hibernate.impl.BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
[DEBUG] 19 Oct 10:50:23.943 AM main [net.sf.hibernate.impl.BatcherImpl] closing statement
[DEBUG] 19 Oct 10:50:24.034 AM main [net.sf.hibernate.loader.Loader] total objects hydrated: 0
[DEBUG] 19 Oct 10:50:24.034 AM main [net.sf.hibernate.impl.SessionImpl] closing session


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 20, 2004 7:14 am 
Newbie

Joined: Mon Oct 04, 2004 7:13 am
Posts: 19
We had the same situation. I posted a question and was advised to use CustomTypes which is what I've done.
ie instead of using many-to-one use a custom type mapper.

see thread:

Use empty string instead of null on optional many-to-one


Top
 Profile  
 
 Post subject: Sample code
PostPosted: Wed Oct 20, 2004 10:53 am 
Newbie

Joined: Tue Oct 19, 2004 12:18 pm
Posts: 4
Mike-
Would you be willing to provide an example of what you did to work around this problem. With the UserType approach.

Thanks in advance.


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.