简体   繁体   中英

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.

In my database the "Auteur_Id" type is a 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:

@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:

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 ? If it has, make sure use @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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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