java oracle.jdbc.driver.OraclePreparedStatement.setLongInternal抛出无效的列索引

6ss1mwsb  于 2023-01-07  发布在  Java
关注(0)|答案(1)|浏览(136)

从Quarkus2.6.2/Hibernate5.6.1到我们当前的Quarkus2.8.2/Hibernate5.6.8,当更新我们的一个实体时,我们收到无效列索引错误。相同的代码在Quarkus1.13.7/Hibernate5.4.29下没有任何问题。我们正在使用

quarkus.datasource.db-kind=oracle
quarkus.hibernate-orm.dialect = org.hibernate.dialect.Oracle9iDialect

我的问题是,这是否一个问题:
1.甲骨文司机?

  1. hibernate ?
  2. quarkus 斯?
    1.我们的代码有问题吗?
    以下是实体:
@Entity
@Table(name = "USER_PREFERENCES")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@SequenceGenerator(name = "user_preferences_id_sequence", sequenceName = "USER_PREFERENCES_SEQ", allocationSize = 1)
public class Preferences {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_preferences_id_sequence")
    @Column(name = "ID")
    private Long id;

    @Column(name = "TYP")
    private String typ;

    @Column(name = "MODEX")
    private String modex;

    @Column(name = "JSON")
    private String json;
}

下面是通过Liquibase创建的数据库表:

<createTable tableName="USER_PREFERENCES">
    <column name="ID" type="NUMBER(38,0)">
        <constraints nullable="false" primaryKey="true" />
    </column>
    <column name="MODEX" type="VARCHAR2(12)"/>
    <column name="TYP" type="VARCHAR2(100)"/>
    <column name="JSON" type="CLOB"/>
</createTable>

leading to:

ID  NUMBER(38,0)
MODEX   VARCHAR2(12 CHAR)
TYP VARCHAR2(100 CHAR)
JSON    CLOB

调用em.persist(preferences)时,Hibernate在工作版本和非工作版本中创建以下输出:

2022-05-16 08:50:39,914 DEBUG [org.hib.SQL] (executor-thread-1)
    update
        USER_PREFERENCES
    set
        JSON=?,
        MODEX=?,
        TYP=?
    where
        ID=?
Hibernate:
    update
        USER_PREFERENCES
    set
        JSON=?,
        MODEX=?,
        TYP=?
    where
        ID=?
2022-05-16 08:50:39,918 TRACE [org.hib.typ.des.sql.BasicBinder] (executor-thread-1) binding parameter [1] as [VARCHAR] - [{"autoSearch":true,"filter":{"statusId":2,"userId":55,"testProp":"xxx"}}]
2022-05-16 08:50:39,919 TRACE [org.hib.typ.des.sql.BasicBinder] (executor-thread-1) binding parameter [2] as [VARCHAR] - [testB985B]
2022-05-16 08:50:39,921 TRACE [org.hib.typ.des.sql.BasicBinder] (executor-thread-1) binding parameter [3] as [VARCHAR] - [search_prefs]
2022-05-16 08:50:39,923 TRACE [org.hib.typ.des.sql.BasicBinder] (executor-thread-1) binding parameter [4] as [BIGINT] - [11]

在不工作的版本中,这将导致

2022-05-16 09:06:51,292 DEBUG [org.hib.eng.jdb.spi.SqlExceptionHelper] (executor-thread-0) could not update: [de.my.app.preferences.entity.Preferences#11] [update USER_PREFERENCES set JSON=?, MODEX=?, TYP=? where ID=?]: java.sql.SQLException: Ung³ltiger Spaltenindex
        at oracle.jdbc.driver.OraclePreparedStatement.setLongInternal(OraclePreparedStatement.java:5005)
        at oracle.jdbc.driver.OraclePreparedStatement.setLong(OraclePreparedStatement.java:4996)
        at oracle.jdbc.driver.OraclePreparedStatementWrapper.setLong(OraclePreparedStatementWrapper.java:207)
        at io.agroal.pool.wrapper.PreparedStatementWrapper.setLong(PreparedStatementWrapper.java:148)
        at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$1.doBind(BigIntTypeDescriptor.java:46)
        at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:73)
        at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:276)
        at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:271)
        at org.hibernate.persister.entity.AbstractEntityPersister.dehydrateId(AbstractEntityPersister.java:3121)
        at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:3093)
        at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3527)
        ... 139 more
piah890a

piah890a1#

用反勾字符转义列名将解决此问题。

@Column(name = "`JSON`")
private String json;

相关问题