错误的布尔映射休眠 (ArrayIndexOutOfBoundsException)

我有一个具有以下属性的持久书类

I have a persistend Book Class with the following properties

  • PropertyName -> HibernateMappingType -> JavaType
  • id -> 长 -> 长
  • 标题 -> 文本 -> 字符串
  • 作者 -> 字符串 -> 字符串
  • systemId -> 长 -> 长
  • 状态 -> 布尔值 -> 布尔值
  • fullClassification -> 字符串 -> 字符串

我的表格描述如下:

到目前为止,一切似乎都很好,但是当我尝试获取表中的所有值时,我收到以下异常消息:

So far everything seems good, but when I try to fetch all the values in the table I get the following Exception Message:

   20:04:43,832 TRACE BasicExtractor:61 - extracted value ([classifi1_1_0_] : [BIGINT]) - [11]
20:04:43,832 TRACE BasicExtractor:61 - extracted value ([collecti1_2_1_] : [BIGINT]) - [11]
20:04:43,833 TRACE BasicExtractor:61 - extracted value ([book_id1_0_2_] : [BIGINT]) - [1]
20:04:43,839 TRACE BasicExtractor:61 - extracted value ([classifi2_1_0_] : [VARCHAR]) - [Prueba]
20:04:43,841 TRACE BasicExtractor:61 - extracted value ([collecti2_2_1_] : [VARCHAR]) - [Prueba]
20:04:43,841 TRACE BasicExtractor:61 - extracted value ([book_tit2_0_2_] : [LONGVARCHAR]) - [Libro de Prueba (No Existe) ]
20:04:43,842 TRACE BasicExtractor:61 - extracted value ([book_aut3_0_2_] : [LONGVARCHAR]) - [Jonathan Pichardo]
20:04:43,842 TRACE BasicExtractor:61 - extracted value ([book_sys4_0_2_] : [BIGINT]) - [190996]
java.lang.ArrayIndexOutOfBoundsException: 57
    at com.mysql.cj.mysqla.MysqlaUtils.bitToLong(MysqlaUtils.java:68)
    at com.mysql.cj.core.io.MysqlTextValueDecoder.decodeBit(MysqlTextValueDecoder.java:231)
    at com.mysql.cj.jdbc.ResultSetRow.decodeAndCreateReturnValue(ResultSetRow.java:170)
    at com.mysql.cj.jdbc.ResultSetRow.getValueFromBytes(ResultSetRow.java:269)
    at com.mysql.cj.jdbc.BufferRow.getValue(BufferRow.java:349)
    at com.mysql.cj.jdbc.ResultSetImpl.getNonStringValueFromRow(ResultSetImpl.java:813)
    at com.mysql.cj.jdbc.ResultSetImpl.getBoolean(ResultSetImpl.java:904)
    at com.mysql.cj.jdbc.ResultSetImpl.getBoolean(ResultSetImpl.java:908)
    at org.hibernate.type.descriptor.sql.BooleanTypeDescriptor$2.doExtract(BooleanTypeDescriptor.java:59)
    at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47)

等等等等等等

我运行的代码是:

会话会话 = SessionFactoryHandler.buildIfNeeded().打开会话();

Session session = SessionFactoryHandler.buildIfNeeded(). openSession();

    Criteria crit = session.createCriteria( Book.class );

    crit.list();

    session.close();

    SessionFactoryHandler.closeFactory();

据我所知,它发生在 status 属性上,我只是不知道为什么,如果我在 xml 中注释映射属性,它可以完美运行,但是它总是抛出相同的异常相同的索引 57,它不会影响数据库中该列的值(只有一个注册表).

As I understand it is happening on the status property I just don't know why, if I comment the mapping property in the xml it works perfectly but with it it throws always the same exception with the same index 57, it doesn't make a difference the value of that column in the database (which has only one registry).

映射文件如下:

<hibernate-mapping package="com.cetys.librarymanagement">
    <class name="com.cetys.librarymanagement.Core.DomainModels.Book" table="book">
        <meta attribute="class-description">
            This class contains the whole description of a Book,
            according to the specification in ALTAIR system.
        </meta>
        <id name="id" type="long" column="book_id">
        </id>
        <property name="title" column="book_title" type="text" length="500" not-null="true"/>
        <property name="author" column="book_author" type="text" not-null="true"/>
        <property name="systemId" column="book_system_id" type="long" not-null="true"/>
        <property name="status" column="book_status" type="boolean" not-null="true"/>
        <property name="fullClassification" column="book_full_classification" 
                  type="string" not-null="true"/>

        <many-to-one name="classification" column="classification_id" 
                     class="com.cetys.librarymanagement.Core.DomainModels.Classification" not-null="true" 
                     unique="false" cascade="save-update" fetch="join"/>
        <many-to-one name="collection" column="collection_id"
                     class="com.cetys.librarymanagement.Core.DomainModels.Collection" not-null="false" 
                     unique="false" cascade="save-update" fetch="join"/>
    </class>
</hibernate-mapping>

有什么想法吗?

推荐答案

据我所知,您正在尝试将数据库中的 BIT 类型映射到休眠代码中的布尔值.

From what I see you are trying to map the BIT type in Database to Boolean in your hibernate code.

从 5.0.3 版开始,MySQL 存在一个带有 BIT 值的错误,因为它不存储单个 BIT 值.它存储诸如 SET 或 ENUM 之类的内容.当您进行数值比较时,这通常会引发问题.更多详情请点击此处

There is a bug in MySQL with BIT Value, from version 5.0.3 onwards, in that it does not store a single BIT value. It stores something like SET or ENUM. And that often throws up issues, when you are doing a numeric value comparison. For more details check here

http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/

您可以要求您的 DBA 将数据类型更改为 tinyint,但是如果这不可能,您可以将状态映射从 boolean 更改为 numeric_boolean,就像

You could ask your DBA to change the datatype to tinyint, however if that is not possible, you can change the status mapping from boolean to numeric_boolean, so would be something like

<property name="status" column="book_status" type="numeric_boolean" not-null="true"/>

相关文章