aspose file tools*
The moose likes Object Relational Mapping and the fly likes Invocation of init method failed; nested exception is net.sf.cglib.core.CodeGeneration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Invocation of init method failed; nested exception is net.sf.cglib.core.CodeGeneration" Watch "Invocation of init method failed; nested exception is net.sf.cglib.core.CodeGeneration" New topic
Author

Invocation of init method failed; nested exception is net.sf.cglib.core.CodeGeneration

amishrm sharma
Greenhorn

Joined: Dec 08, 2008
Posts: 7
Hi everybody,

I integrate hibernate code with spring ,and when i execute my main class then i am facing below exception.

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [application-context.xml]: Invocation of init method failed; nested exception is net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
Caused by: net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at net.sf.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:127)
at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:135)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:295)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)


below is my application-context.xml file code

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="url">
<value>jdbcracle:thin:@10.151.50.178:1523:BNPLINK</value>
</property>
<property name="username">
<value>netpay</value>
</property>
<property name="password">
<value>welcome1</value>
</property>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingResources">
<list>
<value>com/jp/spring/orm/emp.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>

<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
</beans>

and below is my mapping file code

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.jp.spring.orm">
<class
name="Emp"
table="PEMP">

<id
name="id"
column="empno"
type="integer">
<generator class="assigned">
</generator>
</id>



<property
name="name"
type="string"
column="ename"
length="30"
/>

<property
name="sal"
type="double"
column="sal"
length="10"
/>

<property
name="deptno"
type="integer"
column="deptno"
length="12"
/>
</class>
</hibernate-mapping>

and pojo class code is

package com.jp.spring.orm;

public class Emp {
private int id;
private String name;
private double sal;
private int deptno;
public int getDeptno() {
return deptno;
}
public void setDeptno(int deptno) {
this.deptno = deptno;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getSal() {
return sal;
}
public void setSal(double sal) {
this.sal = sal;
}


}

and below is main class code
package com.jp.spring.orm;
import org.springframework.aop.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.orm.hibernate3.HibernateTemplate;

public class SpringHibernateDemo {


public static void main(String[] args) {
ApplicationContext apctx = new ClassPathXmlApplicationContext("application-context.xml");
HibernateTemplate jt = (HibernateTemplate)apctx.getBean("hibernateTemplate");

Emp e = new Emp();
e.setId(106);
e.setName("Ankur");
e.setSal(3000);
e.setDeptno(20);
jt.save(e);
System.out.println("the object is saved");
/* to read
System.out.println("here");
Emp e1=(Emp)jt.get(Emp.class,106);

System.out.println(e1.getDeptno()+e1.getName());
*/

}

}


Please help

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Invocation of init method failed; nested exception is net.sf.cglib.core.CodeGeneration