"Found: smallint, expected: integer" Hibernate 对 informix 数据库的验证失败

"Found: smallint, expected: integer" Hibernate's validation of informix database fails on short

我目前正在开发一个项目,其中包含一个对我而言不可变的预先存在的数据库。当我针对数据库进行验证时,我收到一个错误,据我所知,这是不正确的。

我有三个相互作用的对象:

@Embeddable
public class AssessQstnChoiceId implements java.io.Serializable {
  private short assessQstnNum;
  ...
  ...
  // NOTE: smallint->short
  /*
   * These are my attempted "Fixes"
   * @Column(name = "assess_qstn_num", columnDefinition = "SMALLINT")
   * @Type(type="java.lang.Short")
   */
  @Column(name = "assess_qstn_num")
  public short getAssessQstnNum() {
    return this.assessQstnNum;
  }

  public void setAssessQstnNum(short assessQstnNum) {
    this.assessQstnNum = assessQstnNum;
  }
  ...
}

是以下的关键:

@Entity
@Table(name = "assess_qstn_choice")
public class AssessQstnChoice implements java.io.Serializable {
    private AssessQstnChoiceId id;
    private Set<TstQstnRspns> tstQstnRspnses;

    @EmbeddedId
    public AssessQstnChoiceId getId() {
        return this.id;
    }

    public void setId(AssessQstnChoiceId id) {
        this.id = id;
    }
    ...
    ...
    @OneToMany
    @JoinColumns({
      @JoinColumn(name = "qstn_choice_num",nullable = false),
      @JoinColumn(name = "assess_qstn_num",nullable = false),
      @JoinColumn(name = "tst_sctn_num",nullable = false),
      @JoinColumn(name = "assess_tst_id",nullable = false)
    })
    public Set<TstQstnRspns> getTstQstnRspnses() {
        return this.tstQstnRspnses;
    }

    public void setTstQstnRspnses(Set<TstQstnRspns> tstQstnRspnses) {
        this.tstQstnRspnses = tstQstnRspnses;
    }
}

通过@OneToMany 链接到:

@Entity
@Table(name = "tst_qstn_rspns")
public class TstQstnRspns implements java.io.Serializable {
    private AssessQstnChoice assessQstnChoice;
    ...
    ...
    @ManyToOne
    @JoinColumns({
      @JoinColumn(name = "qstn_choice_num", insertable=false, updatable=false),
      @JoinColumn(name = "assess_qstn_num", insertable=false, updatable=false),
      @JoinColumn(name = "tst_sctn_num", insertable=false, updatable=false),
      @JoinColumn(name = "assess_tst_id", insertable=false, updatable=false),
    })
    public AssessQstnChoice getAssessQstnChoice() {
        return this.assessQstnChoice;
    }

    public void setAssessQstnChoice(AssessQstnChoice assessQstnChoice) {
        this.assessQstnChoice = assessQstnChoice;
    }
}

我收到以下错误消息:

org.hibernate.HibernateException: Wrong column type in MYDB.USR.tst_qstn_rspns for column assess_qstn_num. Found: smallint, expected: integer
    at org.hibernate.mapping.Table.validateColumns(Table.java:372)
    at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1336)
    at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:155)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:525)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:372)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:453)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:438)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1627)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1564)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:706)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:663)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:629)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:677)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:548)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:489)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
    at javax.servlet.GenericServlet.init(GenericServlet.java:160)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:663)
    at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1642)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    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)

据我所知,验证应该期待一个 SMALLINT,因为 assessQstnNum 很短。有什么我可能会遗漏的吗?当我给出 columnDefinition="SMALLINT" 和 type = "SMALLINT"

时,我对 SMALLINT 的期望感到特别困惑

事实证明,您还必须告诉 joincolumn 列定义。更改 AssessQstnChoice 的定义以包括列定义修复了该问题。

@ManyToOne
    @JoinColumns({
      @JoinColumn(name = "qstn_choice_num", insertable=false, updatable=false, columnDefinition = "INT"),
      @JoinColumn(name = "assess_qstn_num", insertable=false, updatable=false, columnDefinition = "SMALLINT"),
      @JoinColumn(name = "tst_sctn_num", insertable=false, updatable=false, columnDefinition = "SMALLINT"),
      @JoinColumn(name = "assess_tst_id", insertable=false, updatable=false, columnDefinition = "INT"),
    })
    public AssessQstnChoice getAssessQstnChoice() {
        return this.assessQstnChoice;
    }