-->
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.  [ 5 posts ] 
Author Message
 Post subject: LazyInitializationException-only for object with null value.
PostPosted: Wed Mar 03, 2004 11:18 am 
Newbie

Joined: Wed Dec 10, 2003 11:49 am
Posts: 17
I have an hibernate query that queries a view that i have created by combining 2 tables. So my view will get 2 columns from tableA and 1 column from tableB. The coulmn from tableB could be null for some case and have value for some case. For example

tableA will have serialNumber and connectionType. (and some other columns. see below). tableB will have proxyId as one coulmn (with serial number as the link coulmn between tableA and tableB. (See below))

Only if the connectionType of tableA value is "P" i will have a value in the proxyId coudmn of tableB. If the connectionType of tableA value is "D" then the proxyId will be empt(Null).

When i run my program, it works fine as long as the proxyId value is NOT NULL. Once if the proxyId value is NULL, it throws
"LazyInitializationException".



Here is my view that i have created.

create or replace view dev_info_proxy_dev_list_view as select d.serial_number, d.connection_type, p.proxy_id from device_info d, proxy_device_list p where p.serial_number (+) = d.serial_number;

Here is my map created out ot oracle view

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<!--
Created by Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="com.xerox.hc.model.common.device.DevInfoProxyDevListView"
table="DEV_INFO_PROXY_DEV_LIST_VIEW"
>

<composite-id>
<key-property
name="serialNumber"
column="SERIAL_NUMBER"
type="java.lang.String"
length="20"
/>
<key-property
name="connectionType"
column="CONNECTION_TYPE"
type="java.lang.String"
length="1"
/>
<key-property
name="proxyId"
column="PROXY_ID"
type="java.lang.String"
length="64"
/>
</composite-id>


<!-- associations -->

</class>
</hibernate-mapping>

Here is my query:

Query query = session1.createQuery("from com.xerox.hc.model.common.device.DevInfoProxyDevListView as d where d.serialNumber in ("+sb.toString()+")");


Here are the 2 tables

Table Name : Proxy_device_list



Name Null? Type

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

PROXY_ID NOT NULL VARCHAR2(64)

SERIAL_NUMBER NOT NULL VARCHAR2(15)



Table Name : device_info

Name Null? Type

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

SERIAL_NUMBER NOT NULL VARCHAR2(20)

PRODUCT_CODE VARCHAR2(10)

SITE_ID NUMBER

CONNECTION_TYPE CHAR(1)


basically I have to get serial_number, connection_type,(from device_info table) proxy_id (from proxy_device_list) table even if the serial number in device_info table is not in proxy_device_list table, i want to return a null proxy_id. I had failed in all my attempts to do joins and that's the reason i have careted a view.

It works fine if the proxy_id value is not null. It throws errors only when the proxy_id is null.

Here is the stack trace:

net.sf.hibernate.LazyInitializationException: Hibernate lazy instantiation problem
at net.sf.hibernate.impl.IteratorImpl.next(IteratorImpl.java:98)
at com.xerox.hc.reg2.configuration.session.ConfigurationManagerSessionBean.getDeviceInfo(ConfigurationManagerSessionBean.java:248)
at com.xerox.hc.reg2.configuration.session.ConfigurationManagerSessionBean.isDeviceDCSRegistered(ConfigurationManagerSessionBean.java:160)
at com.xerox.hc.reg2.configuration.session.ConfigurationManagerSessionBean_n2y8kg_EOImpl.isDeviceDCSRegistered(ConfigurationManagerSessionBean_n2y8kg_EOImpl.java:534)
at com.xerox.hc.reg2.configuration.session.ConfigurationManagerSessionBean_n2y8kg_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.ServerRequest.sendReceive(ServerRequest.java:166)
at weblogic.rmi.internal.BasicRemoteRef.invoke(BasicRemoteRef.java:138)
at com.xerox.hc.reg2.configuration.session.ConfigurationManagerSessionBean_n2y8kg_EOImpl_812_WLStub.isDeviceDCSRegistered(Unknown Source)
at com.xerox.hc.webservices.provisionrequest.session.ProvisionRequestSessionBean.isDeviceDCSRegistered(ProvisionRequestSessionBean.java:183)
at com.xerox.hc.webservices.provisionrequest.session.ProvisionRequestSessionBean_ja994w_EOImpl.isDeviceDCSRegistered(ProvisionRequestSessionBean_ja994w_EOImpl.java:998)
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 weblogic.webservice.component.slsb.SLSBInvocationHandler.invoke(SLSBInvocationHandler.java:88)
at weblogic.webservice.core.handler.InvokeHandler.handleRequest(InvokeHandler.java:104)
at weblogic.webservice.core.HandlerChainImpl.handleRequest(HandlerChainImpl.java:143)
at weblogic.webservice.core.DefaultOperation.process(DefaultOperation.java:531)
at weblogic.webservice.server.Dispatcher.process(Dispatcher.java:204)
at weblogic.webservice.server.Dispatcher.doDispatch(Dispatcher.java:176)
at weblogic.webservice.server.Dispatcher.dispatch(Dispatcher.java:96)
at weblogic.webservice.server.WebServiceManager.dispatch(WebServiceManager.java:98)
at weblogic.webservice.server.servlet.WebServiceServlet.serverSideInvoke(WebServiceServlet.java:298)
at weblogic.webservice.server.servlet.ServletBase.doPost(ServletBase.java:485)
at weblogic.webservice.server.servlet.WebServiceServlet.doPost(WebServiceServlet.java:268)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
at com.xerox.hc.weblogic.LogFilter.doFilter(LogFilter.java:70)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6356)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
Caused by: net.sf.hibernate.UnresolvableObjectException: No row with the given identifier exists: com.xerox.hc.model.common.device.DevInfoProxyDevListView@1f1b072[serialNumber=2UP000001,connectionType=D,proxyId=<null>], of class: com.xerox.hc.model.common.device.DevInfoProxyDevListView
at net.sf.hibernate.UnresolvableObjectException.throwIfNull(UnresolvableObjectException.java:37)
at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1876)
at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:68)
at net.sf.hibernate.type.EntityType.resolveIdentifier(EntityType.java:215)
at net.sf.hibernate.type.EntityType.nullSafeGet(EntityType.java:154)
at net.sf.hibernate.impl.IteratorImpl.postNext(IteratorImpl.java:72)
at net.sf.hibernate.impl.IteratorImpl.next(IteratorImpl.java:92)
... 39 more

BTW, i am using hibernate 2.0 and my IDE is Intellij with jdk 1.4.5_05 and oracle 8.1.7.4

Anyhelp would be really appreciated


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 1:27 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Caused by: net.sf.hibernate.UnresolvableObjectException: No row with the given identifier exists: com.xerox.hc.model.common.device.DevInfoProxyDevListView@1f1b072[serialNumber=2UP000001,connectionType=D,proxyId=<null>], of class: com.xerox.hc.model.common.device.DevInfoProxyDevListView

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 3:59 pm 
Newbie

Joined: Wed Dec 10, 2003 11:49 am
Posts: 17
Thanks for your response.

Does it means that hibernate can't handle back a null object?

Can i create a oracle view (that joins 2 tables and gives me back what i want) and create map and java object off of that view?

If i can do that, then i should be able to use that java object to do HQL and get the output. Even in that case, i know for some rows, the proxyID will be null. But i still want to see that row with null proxyId instead of hibernate throws an error.

Elango


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 4:09 pm 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
See http://forum.hibernate.org/viewtopic.ph ... highlight=

Have you tried mapping it using a one-to-many mapping as suggested? You can then do an outer join in your HQL. As I have mentioned in the previous forum - I don't think it's good practice to include a nullable property/column in primary key definition/composite key.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 09, 2004 11:48 am 
Newbie

Joined: Wed Dec 10, 2003 11:49 am
Posts: 17
Yes, i got it working with one-to-many mapping.

But still i didn't get answer to my question.

1. Can i use oracle view to create a map and query that object and get the result? I think i should be able to do it.

2. I think you mis-understood my table structure.

The device_info table has got serial_number (PK), product_Code, Connection_Type and site_id.

the proxy_device_list table has got proxy_id and serial_number. Both of them are PK (as composite PK). Serial_number is also an FK for device_info table. proxy_id is an FK for proxy table (i didn't explain that here).

in here, the proxy_device_list columns are never going to be null when you just talk about this table.

Device_info table will always be populated when ever a new device is registered with connection type = "D" or "P". But the proxy_device_list table will be populated only if the connection type is "P".
Other words, device_info table is the super set and proxy_device_list table is subset. Means, there are some devices in the device_info table that may not be in proxy_device_list table.

When you query (input = list of serial numbers) both the device_info table and proxy_device_list table to get serial_number, connection_type (from device_info table) and proxy_id from proxy_device_list table, you may get null proxy_id as because the serial number is not in the proxy_device_list table and hence the proxy_id.

This is what exactly happening in this case (proxyId=null). It doesn't mean that i am allowing null in the composite key. it is because when you join 2 tables, you may get null.

Thanks
Elango


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