hibernate - java.sql.SQLException : Invalid value for getInt() - 'foo'

标签 hibernate jpa integer sqlexception many-to-one

我遇到此错误“getInt() - 'sirocodir' 的值无效”,我在许多论坛中进行了搜索,但没有对我的案例做出回应。

在我的数据库中,“Auteur_Id”类型是 varchar(20)。

我的工厂实体:

@Entity
@Table(name = "Factures")
public class Factures implements java.io.Serializable {

private Collaborateurs collaborateurs;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "Auteur_Id", nullable = false)
public Collaborateurs getCollaborateurs() {
    return this.collaborateurs;
}

public void setCollaborateurs(Collaborateurs collaborateurs) {
    this.collaborateurs = collaborateurs;
}

我的合作者实体:

@OneToMany(fetch = FetchType.LAZY, mappedBy = "collaborateurs")
public Set<Factures> getfactures() {
    return this.factures;
}

public void setfactures(Set<Factures> factures) {
    this.factures = factures;
}

我的服务:

@Transactional(readOnly=true)
public List<Factures> AllFacturesContratsClient() {

    return sessionFactory.getCurrentSession()
            .createQuery("from Factures").list();
}

登录tomcat:

Caused by: java.sql.SQLException: Invalid value for getInt() - 'sirocodir'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2725)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2813)
at org.apache.commons.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:237)
at org.hibernate.type.IntegerType.get(IntegerType.java:51)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:186)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:175)
at org.hibernate.type.ManyToOneType.hydrate(ManyToOneType.java:158)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2267)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1443)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1371)
at org.hibernate.loader.Loader.getRow(Loader.java:1271)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:619)
at org.hibernate.loader.Loader.doQuery(Loader.java:745)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
at org.hibernate.loader.Loader.doList(Loader.java:2449)
... 126 more

最佳答案

Collaborateurs 类中是否有任何枚举类型? 如果有,请确保使用 @Enumerated(EnumType.STRING)

关于hibernate - java.sql.SQLException : Invalid value for getInt() - 'foo' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23866966/

相关文章:

java - 使用 JPA 在 Spring 中进行事务和回滚

java - 仅在保存实体时制作 transient 列

java - 从 PostgreSQL 流式传输行(带获取大小)

java - 如果计算的哈希码超过 INTEGER MAX LIMIT 会怎样?

java - 类型不匹配 : cannot convert from Integer to int

hibernate - 无法在 GWT + Hibernate + MySQL 项目中配置 MySQL 数据源

java - 如何手动设置自动生成的 ID?

java - 如何使用带有无效返回参数的 JPA 2.1 @NamedStoredProcedureQueries?

java - Hibernate @OneToOne 不映射 id

c - 从用户那里读取号码