-->
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.  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Invocation of init method failed; nested exception is java.l
PostPosted: Fri Nov 17, 2006 4:14 am 
Newbie

Joined: Fri Nov 17, 2006 3:44 am
Posts: 12
Location: India
Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: net.sf.cglib.proxy.Enhancer.setInterceptDuringConstruction(Z)V


I have hibernate2 replaced with hibernate3.jar in my classpath and changed all net.sf to org.hibernate
Iam using spring for creating sessionfactory..

Any help..?

Dijo Ignatious


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 4:34 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
You're trying to migrate your code this way ? I didn't do it, so I'm not sure it wouldn't work, but I think there are more differences than swapping jars from h2 to h3 and net.sf to org.hibernate...

About your problem, it does not seem very complex : do you have the right version of cglib in your classpath ? In fact, the error you're getting seems to say it found the class, but not the method in this class it was looking for.

Maybe trying to migrate like you do is possible using org.hibernate.classic.Session, instead of the org.hibernate.Session, but I do not know much of this.

Let me know what it gives :)

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Last edited by batmat on Thu Nov 23, 2006 6:06 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Transaction management
PostPosted: Wed Nov 22, 2006 5:54 am 
Newbie

Joined: Fri Nov 17, 2006 3:44 am
Posts: 12
Location: India
I am using hibernate2 with spring I want to implement transaction management. let me point out wat I was done so far..

1) <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="dataSource"><ref local="appDataSource"/></property>
<property name="mappingResources">
<list>
<value>model/User.hbm.xml</value> </list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
net.sf.hibernate.dialect.PostgreSQLDialect
</prop>
</props>
</property>
</bean>

<bean id="myTxManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>

<bean id="login_user_dao" class="DAOImpl.UserDAOImpl">
<property name="transactionManager"><ref local="myTxManager"/></property>
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>

//==========Java method-======//

public String login()
{

UserDAOImpl userDAOImpl = (UserDAOImpl)appContext.getBean("login_user_dao");
UserDepotRightDAOImpl userdepotDAOImpl = (UserDepotRightDAOImpl)appContext.getBean("user_depot_right_dao");
userlist = userDAOImpl.findValidUser(badgeNo,password);
}

//========DAO impl====//
public Collection findValidUser(Integer id,String password)
{
String name[] = {"id","password"};
Object object[]= {id,password};

return (Collection)getHibernateTemplate().findByNamedQuery("user.findValidUser",name,object);

}


my question is What should I do to implement Transaction managemnet in DAOimplementation..?????

Any Help..?


Top
 Profile  
 
 Post subject: Re: Transaction management
PostPosted: Thu Nov 23, 2006 6:17 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
dijo wrote:
I am using hibernate2 with spring I want to implement transaction management. let me point out wat I was done so far..


I don't understand. Didn't you say you were now using hibernate3 instead of hibernate2 ?

About transaction management, you should consider using TransactionProxyFactoryBean class. This is the one that manages automatic tx demarcation. We use it without any problems, excerpt from our conf :

Code:
<bean id="serviceClientTarget" class="fr.mipih.formationj2ee.client.services.serviceclient.implementation.ServiceClient">
   <property name="subService" ref="clientDao" />
   <property name="transactionManager" ref="transactionManager" />
</bean>
<bean id="serviceClient" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
   <property name="target" ref="serviceClientTarget" />
   <property name="transactionAttributes">
      <props>
         <prop key="store">PROPAGATION_REQUIRED</prop>
         <prop key="delete">PROPAGATION_REQUIRED</prop>
         <prop key="load">PROPAGATION_REQUIRED</prop>
         <prop key="find">PROPAGATION_REQUIRED,readOnly</prop>
      </props>
   </property>
</bean>


You have to define an interface for your service class. Then just get the proxy (here id="serviceClient"), never get directly the serviceClientTarget, that's to say. This is this proxy which will manage the tx demarcation.

I would also recommend you having a service layer in addition to your dao. Dao should not contain business logic, but just data access code (remember DAO means data access object).

Then in your service layer, you would not have to care about the type of data access is under (raw jdbc, file, or hibernate) but just keep on concentrate on business code.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject: org.hibernate.PropertyAccessException: IllegalArgumentExcep
PostPosted: Tue Nov 28, 2006 1:33 am 
Newbie

Joined: Fri Nov 17, 2006 3:44 am
Posts: 12
Location: India
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of model.User.id


I tried to migrate hibernate 2 to hibernate3 fixing all the issues but at the time of loading my application this error occried. can any one point out wat is this..????


Top
 Profile  
 
 Post subject: Caused by: java.lang.IllegalArgumentException:
PostPosted: Tue Nov 28, 2006 2:18 am 
Newbie

Joined: Fri Nov 17, 2006 3:44 am
Posts: 12
Location: India
hi all...

when i try to load my parent table user.java and child table userdepotright.java iam getting this exception...

SEVERE: Could not execute action
org.springframework.orm.hibernate3.HibernateSystemException: IllegalArgumentException occurred calling getter of model.User.id; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of model.User.id
Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of model.User.id


my parent table->User.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>

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

<hibernate-mapping
>
<class
name="model.User"
table="users"
>

<id
name="id"
column="id"
type="java.lang.Integer"
>
<generator class="assigned">
</generator>
</id>

<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="name"
/>

<property
name="password"
type="java.lang.String"
update="true"
insert="true"
column="password"
/>

<property
name="region"
type="java.lang.String"
update="true"
insert="true"
column="region"
/>

<property
name="area"
type="java.lang.String"
update="true"
insert="true"
column="area"
/>

<set
name="userDepotRights"
lazy="true"
inverse="true"
cascade="all"
sort="unsorted"
>

<key
column="user_id"
>
</key>

<one-to-many
class="model.UserDepotRight"
/>

</set>


</class>

<query name="user.findValidUser"><![CDATA[
from User as user where user.id=:id and user.password =:password
]]></query>

</hibernate-mapping>

//===================//

my child table-------------->

<?xml version="1.0" encoding="UTF-8"?>

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

<hibernate-mapping
>
<class
name="model.UserDepotRight"
table="user_depot_rights"
>

<id
name="id"
column="id"
type="java.lang.Integer"
>
<generator class="assigned">
</generator>
</id>

<many-to-one
name="mktDstntnMstr"
class="model.MktDstntnMstr"
cascade="none"
outer-join="auto"
update="true"
insert="true"
>
<column
name="depot_id"
/>
</many-to-one>

<many-to-one
name="user"
class="model.User"
cascade="none"
outer-join="auto"
update="true"
insert="true"
>
<column
name="user_id"
/>
</many-to-one>

</class>

<query name="depot.findUserDepots"><![CDATA[
from UserDepotRight as userdepo where userdepo.user =:userId
]]></query>

</hibernate-mapping>



Help me ....

Dijo Ignatious


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 2:38 am 
Regular
Regular

Joined: Tue May 16, 2006 3:32 am
Posts: 117
Post the code that you are using to load.

This error normally happens when a wrong object is passed e.g. an Integer when it was expecting a User.

If you are using 'depot.findUserDepots' to load, are you setting the User correctly?


Top
 Profile  
 
 Post subject: Caused by: org.hibernate.PropertyAccessException: IllegalArg
PostPosted: Tue Nov 28, 2006 3:10 am 
Newbie

Joined: Fri Nov 17, 2006 3:44 am
Posts: 12
Location: India
This is my collection to load users-->



public Collection findUserDepots(Integer userId) {
return getHibernateTemplate().findByNamedQueryAndNamedParam("depot.findUserDepots","userId",userId);
}

This is my HQL--->

@hibernate.query name="depot.findUserDepots" query="from UserDepotRight as userdepo
* where userdepo.user =:userId"



Dijo Ignatious


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 3:24 am 
Regular
Regular

Joined: Tue May 16, 2006 3:32 am
Posts: 117
Try

Code:
@hibernate.query name="depot.findUserDepots" query="from UserDepotRight as userdepo where userdepo.user.id =:userId"



userdepo.user.id instead of userdepo.user


Top
 Profile  
 
 Post subject: SEVERE: could not initialize proxy - the owning Session was
PostPosted: Tue Nov 28, 2006 3:42 am 
Newbie

Joined: Fri Nov 17, 2006 3:44 am
Posts: 12
Location: India
Jayesh,

I got this error..

Nov 28, 2006 1:09:34 PM org.hibernate.LazyInitializationException <init>
SEVERE: could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:60)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:172)
at model.MktDstntnMstr$$EnhancerByCGLIB$$30bad24f.getDstName(<generated>)

Dijo Ignatious


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 3:56 am 
Regular
Regular

Joined: Tue May 16, 2006 3:32 am
Posts: 117
Is this error related to the change above or is this some other error?

The default lazy settings for Hibernate3 are different from Hibernate2. Your code should be able to handle this change correctly or you can specify lazy="false" explicitly.

See

"Metadata Changes
Association fetching strategies"

in http://www.hibernate.org/250.html

Try with lazy="false" for many-to-one 'user' in model.UserDepotRight.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 4:51 am 
Newbie

Joined: Fri Nov 17, 2006 3:44 am
Posts: 12
Location: India
Jayesh,


I changed lazy="false" from true..

see the changes

/**
* @hibernate.set
* lazy="false"
* inverse="true"
* cascade="all"
* @hibernate.collection-key
* column="depot_id"
* @hibernate.collection-one-to-many
* class="model.UserDepotRight"
*
*/
public Set getUserDepotRights() {
return this.userDepotRights;
}

public void setUserDepotRights(Set userDepotRights) {
this.userDepotRights = userDepotRights;
}


but still that error comming....

Nov 28, 2006 2:18:38 PM org.hibernate.LazyInitializationException <init>
SEVERE: could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:60)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:172)
at model.MktDstntnMstr$$EnhancerByCGLIB$$23e9a791.getDstName(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 4:59 am 
Regular
Regular

Joined: Tue May 16, 2006 3:32 am
Posts: 117
I meant this:

add lazy="false" here

Code:
<many-to-one
name="user"
class="model.User"
cascade="none"
outer-join="auto"
update="true"
insert="true"
>
<column
name="user_id"
/>
</many-to-one>



Please read the link I posted above. You do not have to change any lazy setting if it was working in Hibernate2.

I suggest that you:

'Put default-lazy="false" on all your hibernate-mapping elements.'


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 5:05 am 
Regular
Regular

Joined: Tue May 16, 2006 3:32 am
Posts: 117
Do this for all your mapping files:

Code:
<hibernate-mapping
...
         default-lazy="false"                   
/>


If your code works in Hibernate2 then with this change it would work in Hibernate3 also.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 5:52 am 
Newbie

Joined: Fri Nov 17, 2006 3:44 am
Posts: 12
Location: India
Jayesh,

Made changes as you told..for all mapping elements. Please note Iam using "xdoclet" for generating mapping files..:):)

<many-to-one
default-lazy="false"
name="user"
class="model.User"
cascade="none"
outer-join="auto"
update="true"
insert="true"
>
<column
name="user_id"
/>
</many-to-one>


but at the time of mapping it says-->

SEVERE: Error parsing XML: XML InputStream(49) Attribute "default-lazy" must be declared for element type "many-to-one".

Dijo :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 18 posts ]  Go to page 1, 2  Next

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.