简体   繁体   English

java.sql.SQLException:getInt()的值无效 - 'foo'

[英]java.sql.SQLException: Invalid value for getInt() - 'foo'

I have this error "Invalid value for getInt() - 'sirocodir'" , i have search in many forum but no response for my case. 我有这个错误“getInt()的无效值 - 'sirocodir'”,我在很多论坛搜索但我的情况没有回复。

In my database the "Auteur_Id" type is a varchar(20). 在我的数据库中,“Auteur_Id”类型是varchar(20)。

My Facture Entity: 我的制作实体:

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

My Collaborateurs entity: 我的Collaborateurs实体:

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

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

My service: 我的服务:

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

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

Log tomcat: 记录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

Do you have any enum type in the class Collaborateurs ? Collaborateurs课程中你有任何枚举类型吗? If it has, make sure use @Enumerated(EnumType.STRING) 如果有,请确保使用@Enumerated(EnumType.STRING)

I got this after making a schema change. 在进行架构更改后我得到了这个。 Probably the migration didn't work right. 可能迁移工作不正常。 After dropping the table and regenerating it, the error went away. 丢弃表并重新生成后,错误就消失了。

This exception also occurs due to incorrect mapping between entities. 由于实体之间的映射不正确,也会发生此异常。 In our case we had wrong relationship mapping between two entities. 在我们的例子中,我们在两个实体之间的关系映射错误 We resolved this by correcting relationship among entities. 我们通过纠正实体之间的关系解决了这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM