-->
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.  [ 7 posts ] 
Author Message
 Post subject: Caused by: java.lang.IllegalArgumentException
PostPosted: Mon Mar 27, 2006 5:25 pm 
Beginner
Beginner

Joined: Mon Mar 27, 2006 3:44 pm
Posts: 26
I am relatively new to hibernate. I am evaluating hibernate as O/R tool for my company. I have a legacy database and I am trying out a simple load operation using composite key. I have a primary class created by middle gen
Hibernate version:
3.1

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" >

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

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="com.sungard.octagon.maintenance.Dictionary"
table="dictionary"
>

<composite-id name="comp_id" class="com.sungard.octagon.maintenance.Dictiona
ryPK">
<key-property
name="DictCode"
column="dict_code"
type="java.lang.String"
length="12"
/>
<key-property
name="SubCode"
column="sub_code"
type="java.lang.String"
length="12"
/>
</composite-id>

<property
name="codeDesc"
type="java.lang.String"
column="code_desc"
not-null="true"
length="30"
/>
<property
name="subDesc"
type="java.lang.String"
column="sub_desc"
not-null="true"
length="30"
/>
<property
name="updateUser"
type="java.lang.String"
column="update_user"
not-null="true"
length="12"
/>
<property
name="updateDate"
type="java.sql.Date"
column="update_date"
not-null="true"
length="26"
/>

<!-- Associations -->
<!-- derived association(s) for compound key -->
<!-- end of derived association(s) -->


</class>
</hibernate-mapping>

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

dictPk = new DictionaryPK();
System.out.println("After PK1");
dictPk.setDictCode(dictCode);
System.out.println("After setDictCode"+ dictCode);
dictPk.setSubCode(subCode);
System.out.println("After setSubCode"+ subCode);
Dictionary dict = new Dictionary();
System.out.println("After dict init");
dict.setComp_id(dictPk);
System.out.println("After setComp_id dictcode="+ dict.ge
tComp_id().getDictCode());
//dictData = (Dictionary) session.load(Dictionary.class,
dictPk);
dictData = (Dictionary) session.load(Dictionary.class,di
ct);
Full stack trace of any exception that occurs:
After session open---|#]

[#|2006-03-27T15:15:40.710-0600|SEVERE|sun-appserver-pe8.1_01|org.hibernate.prop
erty.BasicPropertyAccessor|_ThreadID=29;|IllegalArgumentException in class: com.
sungard.octagon.maintenance.DictionaryPK, getter method of property: DictCode|#]

[#|2006-03-27T15:15:40.713-0600|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=29;|
Property Access Exception in class: class com.sungard.octagon.maintenance.Dictio
naryPK|#]

[#|2006-03-27T15:15:40.714-0600|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=29;|
Property Access Exception in property: DictCode|#]

[#|2006-03-27T15:15:40.714-0600|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=29;|
Property Access Exception in class: IllegalArgumentException occurred calling ge
tter of com.sungard.octagon.maintenance.DictionaryPK.DictCode|#]

[#|2006-03-27T15:15:40.718-0600|WARNING|sun-appserver-pe8.1_01|javax.enterprise.
system.stream.err|_ThreadID=29;|org.hibernate.PropertyAccessException: IllegalAr
gumentException occurred calling getter of com.sungard.octagon.maintenance.Dicti
onaryPK.DictCode
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPro
pertyAccessor.java:171)
at org.hibernate.tuple.AbstractComponentTuplizer.getPropertyValue(Abstra
ctComponentTuplizer.java:121)
at org.hibernate.tuple.AbstractComponentTuplizer.getPropertyValues(Abstr
actComponentTuplizer.java:133)
at org.hibernate.tuple.PojoComponentTuplizer.getPropertyValues(PojoCompo
nentTuplizer.java:88)
at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java
:307)
at org.hibernate.type.ComponentType.getHashCode(ComponentType.java:158)
at org.hibernate.engine.EntityKey.getHashCode(EntityKey.java:69)
at org.hibernate.engine.EntityKey.<init>(EntityKey.java:42)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEv
entListener.java:76)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:869)
Name and version of the database you are using:
Ingres 2.6

The generated SQL (show_sql=true):
Nothing generated
Debug level Hibernate log excerpt:

I have tested the connectivity to the database using other simple hibernate tests and they worked fine
The java files are as follows
package com.sungard.octagon.maintenance;
// Generated Mar 22, 2006 1:45:36 PM by Hibernate Tools 3.1.0 beta3

import java.sql.Timestamp;


/**
* Dictionary generated by hbm2java
*/

public class Dictionary implements java.io.Serializable {


// Fields

private DictionaryPK comp_id;
private String codeDesc;
private String subDesc;
private String updateUser;
private Timestamp updateDate;


// Constructors

/** default constructor */
public Dictionary() {
}


/** full constructor */
public Dictionary(DictionaryPK comp_id, String codeDesc, String subDesc, Str
ing updateUser, Timestamp updateDate) {
this.comp_id = comp_id;
this.codeDesc = codeDesc;
this.subDesc = subDesc;
this.updateUser = updateUser;
this.updateDate = updateDate;
}



// Property accessors

public DictionaryPK getComp_id() {
return this.comp_id;
}

public void setComp_id(DictionaryPK comp_id) {
this.comp_id = comp_id;
}

public String getDictCode() {
return this.comp_id.getDictCode();
}

public void setDictCode(String dictCode) {
this.comp_id.setDictCode(dictCode);
}

public String getSubCode() {
return this.comp_id.getSubCode();
}

public void setSubCode(String subCode) {
this.comp_id.setSubCode(subCode);
}
public String getCodeDesc() {
return this.codeDesc;
}

public void setCodeDesc(String codeDesc) {
this.codeDesc = codeDesc;
}

public String getSubDesc() {
return this.subDesc;
}

public void setSubDesc(String subDesc) {
this.subDesc = subDesc;
}

public String getUpdateUser() {
return this.updateUser;
}

public void setUpdateUser(String updateUser) {
this.updateUser = updateUser;
}

public Timestamp getUpdateDate() {
return this.updateDate;
}

public void setUpdateDate(Timestamp updateDate) {
this.updateDate = updateDate;
}

package com.sungard.octagon.maintenance;
// Generated Mar 22, 2006 1:45:38 PM by Hibernate Tools 3.1.0 beta3



/**
* DictionaryPK generated by hbm2java
*/

public class DictionaryPK implements java.io.Serializable {


// Fields

private String DictCode;
private String SubCode;


// Constructors

/** default constructor */
public DictionaryPK() {
}


/** full constructor */
public DictionaryPK(String dictCode, String subCode) {
System.out.println("In DictionaryPK");
this.DictCode = dictCode;
this.SubCode = subCode;
System.out.println("After DictionaryPK");
}



// Property accessors

public String getDictCode() {
return this.DictCode;
}

public void setDictCode(String dictCode) {
this.DictCode = dictCode;
}

public String getSubCode() {
return this.SubCode;
}

public void setSubCode(String subCode) {
this.SubCode = subCode;
}
public boolean equals(Object other) {
if(this == other)
return true;
if ( !(other instanceof DictionaryPK) ) return false;
DictionaryPK castOther = (DictionaryPK) other;
if(this.getDictCode().equals(castOther.getDictCode()) &&
this.getSubCode().equals(castOther.getSubCode()))
return true;
return false;
}

public int hashCode() {
return (getDictCode() + getSubCode())
.hashCode();
}

}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 12:40 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
That exception is thrown when the object that has been created isn't of the expected type. Hibernate has used reflection to get one of the Methods representing an accessor in DictionaryPK, but the object that it's passing into getter.invoke() isn't a DictionaryPK object. When you understand that, you easily spot the prime candidate for the bug:
Code:
//dictData = (Dictionary) session.load(Dictionary.class, dictPk);
dictData = (Dictionary) session.load(Dictionary.class, dict);
You've commented out the correct line and left in the wrong one.

When posting, can you make use of code tags and the preview button, please?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 29, 2006 11:20 am 
Beginner
Beginner

Joined: Mon Mar 27, 2006 3:44 pm
Posts: 26
Does not help. I get the following exception. I also have cache enabled. It seems to load the entity from the cache and then fails. This is the debug and error

[#|2006-03-29T09:12:56.577-0600|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=35;|
09:12:56,576 DEBUG DefaultLoadEventListener:153 - loading entity: [com.sungard.o
ctagon.maintenance.Dictionary#component[DictCode,SubCode]{DictCode=ACCT_TYPE, Su
bCode=A}]
|#]

[#|2006-03-29T09:12:56.578-0600|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=35;|09:12:56,578 DEBUG DefaultLoadEventListener:230 - c
reating new proxy for entity
|#]

[#|2006-03-29T09:12:56.580-0600|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=35;|09:12:56,579 DEBUG JDBCContext:225 - after autocomm
it
|#]

[#|2006-03-29T09:12:56.581-0600|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=35;|09:12:56,581 DEBUG ConnectionManager:296 - aggressi
vely releasing JDBC connection
|#]

[#|2006-03-29T09:12:56.582-0600|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=35;|09:12:56,581 DEBUG SessionImpl:434 - after transact
ion completion
|#]

[#|2006-03-29T09:12:56.583-0600|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.container.ejb|_ThreadID=35;|EJB5018: An exception was thrown during an ejb i
nvocation on [DictionaryBean]|#]

[#|2006-03-29T09:12:56.583-0600|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.container.ejb|_ThreadID=35;|
javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseConta
iner.java:2807)
at com.sun.ejb.containers.BaseContainer.checkExceptionNoTx(BaseContainer
.java:2647)
at com.sun.ejb.containers.BaseContainer.checkExceptionBeanMgTx(BaseConta
iner.java:2585)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:
2485)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:81
9)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInv
ocationHandler.java:137)
at $Proxy41.getRow(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(Reflecti
veTie.java:123)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispa
tchToServant(CorbaServerRequestDispatcherImpl.java:648)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispa
tch(CorbaServerRequestDispatcherImpl.java:192)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest
Request(CorbaMessageMediatorImpl.java:1709)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest
(CorbaMessageMediatorImpl.java:1569)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(C
orbaMessageMediatorImpl.java:951)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.call
back(RequestMessage_1_2.java:181)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest
(CorbaMessageMediatorImpl.java:721)
at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.dispatc
h(SocketOrChannelConnectionImpl.java:473)
at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.doWork(
SocketOrChannelConnectionImpl.java:1262)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.
run(ThreadPoolImpl.java:409)
Caused by: java.lang.NullPointerException
at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntity
Tuplizer.java:372)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(Ab
stractEntityPersister.java:3121)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessa
ry(DefaultLoadEventListener.java:232)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultL
oadEventListener.java:173)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEv
entListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:869)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:788)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:781)
at com.sungard.octagon.maintenance.DictionaryBean.getRow(DictionaryBean.
java:130)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.enterprise.security.SecurityUtil$2.run(SecurityUtil.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.enterprise.security.application.EJBSecurityManager.doAsPrivil
eged(EJBSecurityManager.java:950)
at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:158
)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInv
ocationHandler.java:128)
... 16 more
|#]
[/quote][/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 29, 2006 6:41 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
It does help, as it fixed the problem. This is a new problem.

Your new excpetion was caused because a proxy factory wasn't created. The most likely reason that I can think of would have to involve thread safety. Are you loading the object in one thread then referencing it from another? Or worse, creating the session in one thread and using it in another?

P.S. You forgot to use the preview button. Thank you for trying to use code tags, but it didn't work.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 29, 2006 7:25 pm 
Beginner
Beginner

Joined: Mon Mar 27, 2006 3:44 pm
Posts: 26
I think your suggestion did indeed help. It guided me in the right path. I fixed it by using session.get() instead of session.load() I have no idea why load does not work. It uses the cache too. Thanks for your help


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 29, 2006 7:45 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Interesting, but you haven't really solved the problem, you've just masked it. get() essentially calls load(), catches all exceptions, and returns null if there was an exception (it doesn't actually do that, it avoids doing anything that might cause an exception, but functionally, that's what happens).

Another explanation for the exception might be that there was a stale object involved. Is this possible? That you load()ed the object, but part of the object (presumably in another table, possibly via a <join> or <joined-subclass> element?) couldn't be found?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 4:22 pm 
Beginner
Beginner

Joined: Mon Mar 27, 2006 3:44 pm
Posts: 26
I am trying to load a object using a id(Primary key class). If it is not in the cache, it should get it from the database right? From the debug I find that it indeed found it in the cache and loads it. Ater that it fails with the above error. Anyway Session.get() seems to be the better approach if the user is not sure whether the object exists or not. The return value can be checked for null


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