0

私のHibernate ApplicationActiveには、ブール型のフィールドが1つあります。私の Hibernate Bean クラスのコラム

    @Column(name = "ACTIVE")
@Type(type = "org.hibernate.type.YesNoType")
private boolean active;
//Setter and getter  methods

そして、私のサービスクラスの書き込みコードでは...

public void createUser(UserVO userVO) throws Exception {
    --------
    userVO.setActive(false);//setting false..
    ----
    ------//Database insert Code hear..
}

しかし、私は例外を聞いています..

    Caused by: java.sql.BatchUpdateException: Incorrect integer value: 'N' for column 'ACTIVE' at row 1
    at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2045)
    at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1468)
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
    ... 50 more
Caused by: java.sql.SQLException: Incorrect integer value: 'N' for column 'ACTIVE' at row 1
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2683)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2144)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2444)
    at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1997)
    ... 53 more
4

2 に答える 2

0

hibernate types docsから:

org.hibernate.type.YesNoType

ブール値を ('N' | 'n') = false、( 'Y' | 'y' ) = true として JDBC CHAR 型にマップします。

そのため、テーブルの列の型 (tinyint) は値を保持するのに適していません。char または varchar にします。

于 2013-03-22T07:54:06.667 に答える
0

あなたの問題については、2つの解決策があります。

1、タイプ ACTIVE 列が {tinyint} の場合、コードで短い数値を使用する必要があります。

userVO.setActive(Short.valueOf("0")); 

2、コードでブール型を使用する必要がある場合は、change the type of ACTIVE column to {char}

幸運を!

于 2013-03-22T09:02:45.053 に答える