0

我很难解决这个异常

org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.mypackage.campaign.domain.Promotion.id
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:187)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:341)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:4491)
at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:4213)
at org.hibernate.engine.internal.ForeignKeys.isTransient(ForeignKeys.java:209)
at org.hibernate.event.internal.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:495)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:100)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:727)
at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:719)
at org.hibernate.engine.spi.CascadingAction$5.cascade(CascadingAction.java:258)
at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:383)
at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:326)
at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:208)
at org.hibernate.engine.internal.Cascade.cascadeCollectionElements(Cascade.java:412)
at org.hibernate.engine.internal.Cascade.cascadeCollection(Cascade.java:353)
at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:329)
at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:208)
at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:165)
at org.hibernate.event.internal.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:448)
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:293)
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:193)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:126)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:204)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:189)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:756)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:748)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:744)
at com.mypackage.campaign.dao.CampaignDAOImpl.create(CampaignDAOImpl.java:69)
at com.mypackage.campaign.service.CampaignService.create(CampaignService.java:46)
at com.mypackage.campaign.service.CampaignService$$FastClassByCGLIB$$648ccc88.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
at com.mypackage.campaign.service.CampaignService$$EnhancerByCGLIB$$86f80f72.create(<generated>)
at com.mypackage.campaign.service.CampaignServiceTest.createOneElementFromJSONTest(CampaignServiceTest.java:82)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:164)
... 72 more

这些是我的模型类

活动

@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
 *            the id to set
 */
public void setId(Integer id) {
    this.id = id;
}
...
...
/**
 * @return the 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;
}
...
...
}

晋升

@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 the id
     */
    @Id
    @GeneratedValue
    @Column(name = "ID", nullable=false)
    public Integer getId() {
        return id;
    }
    ...
    ...
    /**
     * @return the 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;
    }
}

我的CampaignService课程有这个......

@Transactional(readOnly=true)
public List<Campaign> getCampaignList(){
    return dao.getCampaignList();
}

我的CampaignDAO代码是

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);
}

在执行query.list()时,在我调用服务方法getCampaignList()后发生异常

我无法看到问题出在哪里,所以任何帮助都非常受欢迎......

干杯,

4

0 回答 0