2

当我尝试调用 save 方法时,我的代码中有这个错误,当我在 JBoss 服务器上时,这个方法工作正常,现在我继续使用 tomcat 服务器 7

ERROR: HHH000123: IllegalArgumentException in class:     com.sb.core.beans.CompanyStudies,setter method of property: studyId
Aug 5, 2013 9:24:52 AM org.hibernate.property.BasicPropertyAccessor$BasicSetter set
ERROR: HHH000091: Expected type: java.lang.Integer, actual value:     org.hibernate.id.IdentifierGeneratorHelper$2
org.hibernate.PropertyAccessException: IllegalArgumentException occurred while          calling setter of com.sb.core.beans.CompanyStudies.studyId
at   org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:119)
at org.hibernate.mapping.Component$ValueGenerationPlan.execute(Component.java:436)
at org.hibernate.id.CompositeNestedGeneratedValueGenerator.generate(CompositeNestedGeneratedValueGenerator.java:121)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:120)
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:642)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:635)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:631)
at com.sb.core.dao.impl.CompanyStudiesDAOImpl.addCompanyStudy(CompanyStudiesDAOImpl.java:31)
at com.sb.core.businesslogic.impl.CompanyStudiesServiceImpl.addCompanyStudy(CompanyStudiesServiceImpl.java:26)
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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy42.addCompanyStudy(Unknown Source)
at com.sb.web.managed.beans.CompanyManagedBean.saveCompanyDetail(CompanyManagedBean.java:3612)
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 javax.el.BeanELResolver.invokeMethod(BeanELResolver.java:737)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:467)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:246)
at com.sun.el.parser.AstValue.invoke(AstValue.java:228)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:102)
at   javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:84)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98)
at javax.faces.component.UICommand.broadcast(UICommand.java:311)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
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$BasicSetter.set(BasicPropertyAccessor.java:65)    

我的豆类是

@Entity
@Table(name = "company_studies", catalog = "studybuddyDB")
public class CompanyStudies implements java.io.Serializable {
/**
* 
*/
private static final long serialVersionUID = 1L;
// Fields
private  Integer studyId = 0; 
private CompanyDetail companyDetail; 
private int isActive;
/** default constructor */
public CompanyStudies() {
        
}

/** full constructor */
public CompanyStudies(CompanyDetail companyDetail,int isActive) {
this.setCompanyDetail(companyDetail);
this.setIsActive(isActive);*/
    
    
this.companyDetail = companyDetail;
this.isActive = isActive;
}


// Property accessors

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "study_id", unique = true, nullable = false )

public Integer getStudyId() {
return studyId;
}

public void setStudyId(Integer studyId) {
this.studyId = studyId;
}

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "company_detail_id")
public CompanyDetail getCompanyDetail() {
return companyDetail;
}

public void setCompanyDetail(CompanyDetail companyDetail) {
this.companyDetail = companyDetail;
}

@Id
@Column(name = "isActive", nullable = false)    
public int getIsActive() {
return isActive;
}

public void setIsActive(int isActive) {
this.isActive = isActive;
}

}

请帮我解决这个问题

4

4 回答 4

5

我遇到了同样的错误,

经过一番研究,我得出结论,这取决于两件事。

What DB you are using plus
What @GenericGenerator - what strategy you are using.

我能够通过以下配置解决问题。

DB - MySQL
Changed strategy to increment from native

我的代码如下所示:

@ElementCollection 
@JoinTable(name="USERS_ADDRESSES",
        joinColumns=@JoinColumn(name="USER_ID"))

@GenericGenerator(name="hilogen", strategy="increment")

@CollectionId(columns= {@Column(name="ADDR_ID")}, 
        generator="hilogen", type=@Type(type="long")) 

private List addressList = new ArrayList();

希望这有帮助。

谢谢,萨加尔维亚斯

于 2015-12-23T19:23:48.373 回答
4

一些生成器无法在实际插入之前生成标识符,因此它们从 generate() 方法返回一个特殊的标记对象。该对象表示 Hibernate 应该以不同的方式获取标识符,使用PostInsertIdentifierGenerator.getInsertGeneratedIdentifierDelegate().
尝试使用 a@SequenceGenerator或 a@GenericGenerator

于 2013-08-05T06:12:22.640 回答
0

这显然是格式问题。将 Wrapper 类对象 StudyId 更改为原始 int。

于 2013-08-05T06:11:09.653 回答
0

我尝试了很多解决方案,但这对我有用:

@CollectionId(columns = { @Column(name="HASTYPE_ID") }, generator= "sequence", type=@Type(type="long"))

此活动适用于INTEGER

@CollectionId(columns = { @Column(name="HASTYPE_ID") }, generator= "sequence", type=@Type(type="int"))
于 2017-05-14T19:44:12.250 回答