Spring Data Neo4j - Exception when trying to use @Transactional annotation -


i'm quite new spring data , neo4j, , there don't understand using @transactional annotation. seems must declare empty constructor class annotated 1 of methods @transactional, , need create empty constructor node entities classes transaction use... (and if don't declare empty constructors, exception). but.. maybe i'm missing something. i'll show example, below code example, demonstrates i'm talking (its short spring-data-neo4j setup gets things , running):

my configuration class:

@configuration @componentscan(basepackages={"org.technion.socialrescue.core"}) @importresource("spring-data-context.xml") @enabletransactionmanagement public class defaultapplicationconfig {     @bean(destroymethod = "shutdown")     public graphdatabaseservice graphdatabaseservice() {         return new embeddedgraphdatabase("target/graph.db");     } } 

the spring-data-context.xml file:

<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans"        xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"        xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"        xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd         http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd">       <neo4j:config graphdatabaseservice="graphdatabaseservice" />     <neo4j:repositories base-package="org.technion.socialrescue" /> </beans> 

the class hosts method marked @transactional:

@component("someclass") public class someclass {      public someobjectrepository someobjects;          @autowired     public someclass(someobjectrepository someobjects) {         this.someobjects = someobjects;     }      @transactional     public void somemethod() {         someobjects.save(new someobject("roy"));             } } 

the someobject class (which used node in graph):

@nodeentity public class someobject {      public someobject(string name) {         this.name = name;     }      @graphid     private long id;          @indexed     string name; } 

the someobjectrepository interface:

package org.technion.socialrescue.core;  import org.springframework.data.neo4j.repository.graphrepository;  public interface someobjectrepository extends graphrepository<someobject> {  } 

and code launch application:

public class playground {      public static void main(string[] args) {         annotationconfigapplicationcontext context = new annotationconfigapplicationcontext(defaultapplicationconfig.class);         someclass someclass = (someclass)context.getbean("someclass");         someclass.somemethod();         context.close();     } } 

so, running code above, i'm getting following exception:

exception in thread "main" org.springframework.beans.factory.beancreationexception: error creating bean name 'someclass' defined in file [c:\users\t-rvelic\workspace\social-rescue\target\classes\org\technion\socialrescue\core\someclass.class]: initialization of bean failed; nested exception org.springframework.aop.framework.aopconfigexception: not generate cglib subclass of class [class org.technion.socialrescue.core.someclass]: common causes of problem include using final class or non-visible class; nested exception java.lang.illegalargumentexception: superclass has no null constructors no arguments given     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:527)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:456)     @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:294)     @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:225)     @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:291)     @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:193)     @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:607)     @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:932)     @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:479)     @ org.springframework.context.annotation.annotationconfigapplicationcontext.<init>(annotationconfigapplicationcontext.java:73)     @ org.technion.socialrescue.playground.playground.main(playground.java:13) caused by: org.springframework.aop.framework.aopconfigexception: not generate cglib subclass of class [class org.technion.socialrescue.core.someclass]: common causes of problem include using final class or non-visible class; nested exception java.lang.illegalargumentexception: superclass has no null constructors no arguments given     @ org.springframework.aop.framework.cglibaopproxy.getproxy(cglibaopproxy.java:217)     @ org.springframework.aop.framework.proxyfactory.getproxy(proxyfactory.java:111)     @ org.springframework.aop.framework.autoproxy.abstractautoproxycreator.createproxy(abstractautoproxycreator.java:477)     @ org.springframework.aop.framework.autoproxy.abstractautoproxycreator.wrapifnecessary(abstractautoproxycreator.java:362)     @ org.springframework.aop.framework.autoproxy.abstractautoproxycreator.postprocessafterinitialization(abstractautoproxycreator.java:322)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.applybeanpostprocessorsafterinitialization(abstractautowirecapablebeanfactory.java:407)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1461)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:519)     ... 10 more caused by: java.lang.illegalargumentexception: superclass has no null constructors no arguments given     @ org.springframework.cglib.proxy.enhancer.emitconstructors(enhancer.java:721)     @ org.springframework.cglib.proxy.enhancer.generateclass(enhancer.java:499)     @ org.springframework.cglib.transform.transformingclassgenerator.generateclass(transformingclassgenerator.java:33)     @ org.springframework.cglib.core.defaultgeneratorstrategy.generate(defaultgeneratorstrategy.java:25)     @ org.springframework.cglib.core.abstractclassgenerator.create(abstractclassgenerator.java:216)     @ org.springframework.cglib.proxy.enhancer.createhelper(enhancer.java:377)     @ org.springframework.cglib.proxy.enhancer.create(enhancer.java:285)     @ org.springframework.aop.framework.cglibaopproxy.getproxy(cglibaopproxy.java:205)     ... 17 more 

so tried follow cause exception, , added empty constructor someclass, looks this:

@component("someclass") public class someclass {      public someobjectrepository someobjects;      public someclass() {      }         @autowired     public someclass(someobjectrepository someobjects) {         this.someobjects = someobjects;     }      @transactional     public void somemethod() {         someobjects.save(new someobject("roy"));             } } 

then, launched again app, , got following exception:

exception in thread "main" org.springframework.dao.invaliddataaccessapiusageexception: someobject: entity must have no-arg constructor.; nested exception java.lang.illegalargumentexception: someobject: entity must have no-arg constructor.     @ org.springframework.data.neo4j.support.neo4jexceptiontranslator.translateexceptionifpossible(neo4jexceptiontranslator.java:43)     @ org.springframework.dao.support.chainedpersistenceexceptiontranslator.translateexceptionifpossible(chainedpersistenceexceptiontranslator.java:58)     @ org.springframework.dao.support.dataaccessutils.translateifnecessary(dataaccessutils.java:213)     @ org.springframework.dao.support.persistenceexceptiontranslationinterceptor.invoke(persistenceexceptiontranslationinterceptor.java:163)     @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172)     @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:204)     @ com.sun.proxy.$proxy39.save(unknown source)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source)     @ java.lang.reflect.method.invoke(unknown source)     @ org.springframework.aop.support.aoputils.invokejoinpointusingreflection(aoputils.java:317)     @ org.springframework.aop.framework.reflectivemethodinvocation.invokejoinpoint(reflectivemethodinvocation.java:183)     @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:150)     @ org.springframework.transaction.interceptor.transactioninterceptor$1.proceedwithinvocation(transactioninterceptor.java:96)     @ org.springframework.transaction.interceptor.transactionaspectsupport.invokewithintransaction(transactionaspectsupport.java:260)     @ org.springframework.transaction.interceptor.transactioninterceptor.invoke(transactioninterceptor.java:94)     @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172)     @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:204)     @ com.sun.proxy.$proxy40.save(unknown source)     @ org.technion.socialrescue.core.someclass.somemethod(someclass.java:23)     @ org.technion.socialrescue.core.someclass$$fastclassbycglib$$d9c3b9ef.invoke(<generated>)     @ org.springframework.cglib.proxy.methodproxy.invoke(methodproxy.java:204)     @ org.springframework.aop.framework.cglibaopproxy$cglibmethodinvocation.invokejoinpoint(cglibaopproxy.java:698)     @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:150)     @ org.springframework.transaction.interceptor.transactioninterceptor$1.proceedwithinvocation(transactioninterceptor.java:96)     @ org.springframework.transaction.interceptor.transactionaspectsupport.invokewithintransaction(transactionaspectsupport.java:260)     @ org.springframework.transaction.interceptor.transactioninterceptor.invoke(transactioninterceptor.java:94)     @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172)     @ org.springframework.aop.framework.cglibaopproxy$dynamicadvisedinterceptor.intercept(cglibaopproxy.java:631)     @ org.technion.socialrescue.core.someclass$$enhancerbycglib$$d5a7b8cd.somemethod(<generated>)     @ org.technion.socialrescue.playground.playground.main(playground.java:17) caused by: java.lang.illegalargumentexception: someobject: entity must have no-arg constructor.     @ org.springframework.data.neo4j.support.mapping.abstractconstructorentityinstantiator$1.create(abstractconstructorentityinstantiator.java:87)     @ org.springframework.data.neo4j.support.mapping.abstractconstructorentityinstantiator.createentityfromstate(abstractconstructorentityinstantiator.java:56)     @ org.springframework.data.neo4j.support.mapping.neo4jentitypersister$cachedinstantiator.createentityfromstate(neo4jentitypersister.java:135)     @ org.springframework.data.neo4j.support.mapping.neo4jentitypersister$cachedinstantiator.createentityfromstate(neo4jentitypersister.java:122)     @ org.springframework.data.neo4j.support.mapping.neo4jentityconverterimpl.read(neo4jentityconverterimpl.java:86)     @ org.springframework.data.neo4j.support.mapping.neo4jentitypersister$cachedconverter.read(neo4jentitypersister.java:170)     @ org.springframework.data.neo4j.support.mapping.neo4jentitypersister.createentityfromstate(neo4jentitypersister.java:189)     @ org.springframework.data.neo4j.support.mapping.neo4jentitypersister.persist(neo4jentitypersister.java:244)     @ org.springframework.data.neo4j.support.mapping.neo4jentitypersister.persist(neo4jentitypersister.java:231)     @ org.springframework.data.neo4j.support.neo4jtemplate.save(neo4jtemplate.java:293)     @ org.springframework.data.neo4j.support.neo4jtemplate.save(neo4jtemplate.java:287)     @ org.springframework.data.neo4j.repository.abstractgraphrepository.save(abstractgraphrepository.java:109)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source)     @ java.lang.reflect.method.invoke(unknown source)     @ org.springframework.data.repository.core.support.repositoryfactorysupport$queryexecutormethodinterceptor.executemethodon(repositoryfactorysupport.java:333)     @ org.springframework.data.repository.core.support.repositoryfactorysupport$queryexecutormethodinterceptor.invoke(repositoryfactorysupport.java:318)     @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172)     @ org.springframework.transaction.interceptor.transactioninterceptor$1.proceedwithinvocation(transactioninterceptor.java:96)     @ org.springframework.transaction.interceptor.transactionaspectsupport.invokewithintransaction(transactionaspectsupport.java:260)     @ org.springframework.transaction.interceptor.transactioninterceptor.invoke(transactioninterceptor.java:94)     @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172)     @ org.springframework.dao.support.persistenceexceptiontranslationinterceptor.invoke(persistenceexceptiontranslationinterceptor.java:155)     ... 28 more 

so time, added empty constructor someobject class, looks that:

@nodeentity public class someobject {      public someobject() {      }      public someobject(string name) {         this.name = name;     }      @graphid     private long id;          @indexed     string name; } 

and worked...

but why worked? why had add 2 empty constructors? tried google it, found nothing. want know why behaves that... highly appreciated!

thanks!

your beans being proxied cglib enable transaction management. if i'm not mistaken, cglib needs default constructor able proxy beans. might opt aspectj proxy classes, don't need default constructors.

@enabletransactionmanagement(mode = advicemode.aspectj) 

make sure aspectj on classpath!


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -