当前位置: 首页 > 知识库问答 >
问题:

应为类型:java.lang.Integer,实际值:org.hibernate.id.IdentifierGeneratorHelper$2

易俊远
2023-03-14
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;
}

}

共有1个答案

黄毅
2023-03-14

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

 类似资料:
  • 我使用createSqlQuery接口调用hibernate中的存储过程,并且使用result transformer将结果作为bean获取。下面是我的代码 有时,sp结果返回所有整数值,有时是十进制值,有时是固定的,所以我不能给出具体的数据类型。所以我得到以下异常

  • 您好,我正在使用Spring 4.1.1.RELEASE开发一个web应用程序。所有的Spring配置都是通过注释完成的,除了一点之外,它运行得很好: > 我在项目中有一个包含这些行的config.properties文件 我有一个配置类 和另一个类 属性“filter”的值已成功从属性资源中注入。但是我在属性“计数”上得到了一个例外: 当我将属性“count”的类型更改为String时,它开始工

  • 我正在尝试使用Spring Security在应用程序中实现基于DAO的身份验证。 当我试图登录到应用程序与用户我得到了这个错误: 看着@jcmwright80对这个问题的回答,我明白了我最好将类注释为。完成此操作后,我在登录时出错: 这似乎是一个与在UserDetailsServiceImpl上创建的代理对象相关的问题-我如何才能优雅地解决这个问题? 密码 安全配置的相关部分: UserDeta

  • 我是SpringMVC的新手。我开发了一个执行选择,插入,更新和删除的示例应用程序。 下面是我的Bean类 下面是我的控制器类 下面是我的JSP页面 现在我面临两个问题。输入值并单击“添加学生”按钮后,收到以下错误。

  • 问题内容: 我了解在创建这样的新对象时: 更通用,并且允许更多的可重用性,但是当创建tri时会发生以下情况: 由于Triangle是GeomObject的子类,因此tri还是不是GeomObject?声明的类型如何影响编译?谢谢 add:另一个问题:说我有 Integer n1 = new Integer(3); Object n2 = new Integer(4); System.out.pri

  • 有趣的问题,我传递一个,它抱怨它不匹配类型: 它是这样叫的: