hibernate - @ManyToMany IllegalArgumentException calling getter id -
i'm having hard time solving exception
org.hibernate.propertyaccessexception: illegalargumentexception occurred calling getter of com.mypackage.campaign.domain.promotion.id @ org.hibernate.property.basicpropertyaccessor$basicgetter.get(basicpropertyaccessor.java:187) @ org.hibernate.tuple.entity.abstractentitytuplizer.getidentifier(abstractentitytuplizer.java:341) @ org.hibernate.persister.entity.abstractentitypersister.getidentifier(abstractentitypersister.java:4491) @ org.hibernate.persister.entity.abstractentitypersister.istransient(abstractentitypersister.java:4213) @ org.hibernate.engine.internal.foreignkeys.istransient(foreignkeys.java:209) @ org.hibernate.event.internal.abstractsaveeventlistener.getentitystate(abstractsaveeventlistener.java:495) @ org.hibernate.event.internal.defaultsaveorupdateeventlistener.performsaveorupdate(defaultsaveorupdateeventlistener.java:100) @ org.hibernate.event.internal.defaultsaveorupdateeventlistener.onsaveorupdate(defaultsaveorupdateeventlistener.java:90) @ org.hibernate.internal.sessionimpl.firesaveorupdate(sessionimpl.java:727) @ org.hibernate.internal.sessionimpl.saveorupdate(sessionimpl.java:719) @ org.hibernate.engine.spi.cascadingaction$5.cascade(cascadingaction.java:258) @ org.hibernate.engine.internal.cascade.cascadetoone(cascade.java:383) @ org.hibernate.engine.internal.cascade.cascadeassociation(cascade.java:326) @ org.hibernate.engine.internal.cascade.cascadeproperty(cascade.java:208) @ org.hibernate.engine.internal.cascade.cascadecollectionelements(cascade.java:412) @ org.hibernate.engine.internal.cascade.cascadecollection(cascade.java:353) @ org.hibernate.engine.internal.cascade.cascadeassociation(cascade.java:329) @ org.hibernate.engine.internal.cascade.cascadeproperty(cascade.java:208) @ org.hibernate.engine.internal.cascade.cascade(cascade.java:165) @ org.hibernate.event.internal.abstractsaveeventlistener.cascadeaftersave(abstractsaveeventlistener.java:448) @ org.hibernate.event.internal.abstractsaveeventlistener.performsaveorreplicate(abstractsaveeventlistener.java:293) @ org.hibernate.event.internal.abstractsaveeventlistener.performsave(abstractsaveeventlistener.java:193) @ org.hibernate.event.internal.abstractsaveeventlistener.savewithgeneratedid(abstractsaveeventlistener.java:126) @ org.hibernate.event.internal.defaultsaveorupdateeventlistener.savewithgeneratedorrequestedid(defaultsaveorupdateeventlistener.java:204) @ org.hibernate.event.internal.defaultsaveeventlistener.savewithgeneratedorrequestedid(defaultsaveeventlistener.java:55) @ org.hibernate.event.internal.defaultsaveorupdateeventlistener.entityistransient(defaultsaveorupdateeventlistener.java:189) @ org.hibernate.event.internal.defaultsaveeventlistener.performsaveorupdate(defaultsaveeventlistener.java:49) @ org.hibernate.event.internal.defaultsaveorupdateeventlistener.onsaveorupdate(defaultsaveorupdateeventlistener.java:90) @ org.hibernate.internal.sessionimpl.firesave(sessionimpl.java:756) @ org.hibernate.internal.sessionimpl.save(sessionimpl.java:748) @ org.hibernate.internal.sessionimpl.save(sessionimpl.java:744) @ com.mypackage.campaign.dao.campaigndaoimpl.create(campaigndaoimpl.java:69) @ com.mypackage.campaign.service.campaignservice.create(campaignservice.java:46) @ com.mypackage.campaign.service.campaignservice$$fastclassbycglib$$648ccc88.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) @ com.mypackage.campaign.service.campaignservice$$enhancerbycglib$$86f80f72.create(<generated>) @ com.mypackage.campaign.service.campaignservicetest.createoneelementfromjsontest(campaignservicetest.java:82) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25) @ java.lang.reflect.method.invoke(method.java:597) @ org.junit.runners.model.frameworkmethod$1.runreflectivecall(frameworkmethod.java:45) @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:15) @ org.junit.runners.model.frameworkmethod.invokeexplosively(frameworkmethod.java:42) @ org.junit.internal.runners.statements.invokemethod.evaluate(invokemethod.java:20) @ org.junit.internal.runners.statements.runbefores.evaluate(runbefores.java:28) @ org.springframework.test.context.junit4.statements.runbeforetestmethodcallbacks.evaluate(runbeforetestmethodcallbacks.java:74) @ org.springframework.test.context.junit4.statements.runaftertestmethodcallbacks.evaluate(runaftertestmethodcallbacks.java:83) @ org.springframework.test.context.junit4.statements.springrepeat.evaluate(springrepeat.java:72) @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:231) @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:88) @ org.junit.runners.parentrunner$3.run(parentrunner.java:231) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:60) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:229) @ org.junit.runners.parentrunner.access$000(parentrunner.java:50) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:222) @ org.springframework.test.context.junit4.statements.runbeforetestclasscallbacks.evaluate(runbeforetestclasscallbacks.java:61) @ org.springframework.test.context.junit4.statements.runaftertestclasscallbacks.evaluate(runaftertestclasscallbacks.java:71) @ org.junit.runners.parentrunner.run(parentrunner.java:300) @ org.springframework.test.context.junit4.springjunit4classrunner.run(springjunit4classrunner.java:174) @ org.eclipse.jdt.internal.junit4.runner.junit4testreference.run(junit4testreference.java:50) @ org.eclipse.jdt.internal.junit.runner.testexecution.run(testexecution.java:38) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:467) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:683) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.run(remotetestrunner.java:390) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.main(remotetestrunner.java:197) caused by: java.lang.illegalargumentexception: object not instance of declaring class @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25) @ java.lang.reflect.method.invoke(method.java:597) @ org.hibernate.property.basicpropertyaccessor$basicgetter.get(basicpropertyaccessor.java:164) ... 72 more
these model classes
campaign
@jsonautodetect @entity(name = "campaign") @table(name = "campaign") public class campaign extends genericbo { private static final long serialversionuid = 953174999399568165l; ... ... private list<promotion> promotions = new arraylist<promotion>(); ... ... @id @generatedvalue @column(name = "id", nullable=false) public integer getid() { return id; } /** * @param id * id set */ public void setid(integer id) { this.id = id; } ... ... /** * @return promotionlist */ @jsonmanagedreference("promotion-campaign") @manytomany( targetentity = promotion.class, fetch=fetchtype.eager ) @jointable(name="promotion_campaign", joincolumns = @joincolumn(name="campaign_id", nullable = false, updatable = false), inversejoincolumns = @joincolumn(name="promotion_id", nullable = false, updatable = false) ) @cascade(org.hibernate.annotations.cascadetype.all) public list<promotion> getpromotions() { return promotions; } ... ... }
promotion
@jsonautodetect @entity(name="promotion") @table(name = "promotion") public class promotion extends genericbo { private static final long serialversionuid = -8142378443265756834l; ... ... private list<campaign> campaigns = new arraylist<campaign>(); /** * default constructor */ public promotion(){ } /** * @return id */ @id @generatedvalue @column(name = "id", nullable=false) public integer getid() { return id; } ... ... /** * @return campaigns */ @jsonbackreference("promotion-campaign") @manytomany( fetch=fetchtype.eager, mappedby="promotions", targetentity=campaign.class ) @cascade(org.hibernate.annotations.cascadetype.all) public list<campaign> getcampaigns() { return campaigns; } }
my campaignservice class has this...
@transactional(readonly=true) public list<campaign> getcampaignlist(){ return dao.getcampaignlist(); }
and campaigndao code is
public list<campaign> getcampaignlist() { query query = getsessionfactory().getcurrentsession().createquery("from campaign"); list<campaign> list = query.list(); return (list<campaign>) ((list == null || list.size() == 0) ? collections.emptylist() : list); }
at time query.list() executed exception occurs after call service method getcampaignlist()
i'm not able see problem is, more welcome...
cheers,
Comments
Post a Comment