powerjob-server使用postgres数据库运行,出现job-params这个列是oid字段,导致不能新建任务

具体的错误如下:

at org. springframework . data . repository . core . support . RepositoryFac torySupport$ImpLementat ionMe thodExecutionInterceptor . invoke (RepositoryFactorysupport . java:640)
at org. springframework . aop . framework . ReflectiveMethodInvocation. proceed(RefLectiveMethodInvocation. java:186)
at org. springframework . data . repository . core . support . QueryExecutorMe thodInterceptor . doInvoke (QueryExecutorMethodInterceptor. java:164)
at org. springframework . data . repository . core . support . QueryExecutorMe thodInterceptor . invoke(QueryExecutorMe thodInterceptor . java:139)
at org. springframework . aop. framework . ReflectiveMe thodInvocation. proceed(ReflectiveMethodInvocation. java:186)
at org. springframework . data . projection. DefaultMe thodInvokingNethodInterceptor . invoke(DefauL tMe thodInvokingNethodInterceptor . java:81)
at org. springframework . aop. framework . ReflectiveMe thodInvocation. proceed(ReflectiveMethodInvocation. java:186)
at org. springframework . transaction . interceptor. TransactionInterceptor$1 . proceedWithInvocation(TransactionInterceptor . java:123)
at org. springframework . transaction . interceptor. TransactionAspectSupport . invokeWithinTransaction(TransactionAspectSupport. java:388)
at org. springframework. transaction. interceptor . TransactionInterceptor . invoke(TransactionInterceptor . java:119)
at org. springframework . aop . framework . ReflectiveMe thodInvocation . proceed(RefLectiveMethodInvocation. java:186]
at org. springframework . dao . support . PersistenceExceptionTranslationInterceptor invoke(PersistenceExceptionTranslationInterceptor。java:137)
... 124 common frames omitted
Caused by: org. postgresql. util. PSQLException: ERROR: coLumn "job_ params" is of type oid but expression is of type character varying
建议: You will need
to rewrite or cas
the expression.
位置: 536
at org. postgresql. core . v3. QueryExecutorImpL. receiveErrorResponse(QueryExecutorImpL. java:2532)
at org. postgresql. core . v3. QueryExecutorImpL . processResults(QueryExecutorImpL. java:2267)
at org . postgresql. core . v3. QueryExecutor ImpL. execute (QueryExecutorImpL. java :312)
at org . postgresql. jdbc . PgStatement . executeInternal(PgStatement. java:448)
at org. postgresqL. jdbc . PgStatement . execute (PgStatement. java:369)
at org. postgresql. jdbc . PgPreparedStatement . executeWi thFlags(PaPreparedstatement . java:153)
at org . postgresql. jdbc . PgPreparedStatement . executeUpdate (PgPreparedStatement : java:119)
at com. zaxxer . hikari . pool . ProxyPreparedStatement . executeUpdate(ProxyPreparedStatement . java:61)
at com. zaxxer . hikari . pooL. HikariProxyPreparedStatement . executeUpdate (HikariProxyPreparedStatement. java) <1 internal line>
166 common frames omitted

因为使用者只需要创建数据库,powerjob-server是在运行时自动创建表,所以建表模块基本上是一样的。用mysql没有问题,但是切换成postgres数据库,会导致字段不一致出现错误。

翻阅了很多资料,官方也给了一种解决方法:

  • Caused by: org.postgresql.util.PSQLException: 大型对象无法被使用在自动确认事物交易模式
  • JpaSystemException: Unable to access lob stream

如有类似错误可参考以下 ISSUE

PowerJob连接Postgres数据库出现org.springframework.orm.jpa.JpaSystemException: Unable to access lob stream; nested exception is org.hibernate.HibernateException: Unable to access lob stream · Issue #153 · PowerJob/PowerJob · GitHub

  1. 如果 JPA 已经自动建表,请先删除 powerjob 相关的全部表
  2. 在配置文件中添加 spring.datasource.remote.hibernate.properties.hibernate.dialect=tech.powerjob.server.persistence.config.dialect.PowerJobPGDialect来启用 postgreSQL 专用方言处理器,重新启动 server & 自动建表。

我按照这个步骤来进行操作后,发现还是不能完全解决问题,新建任务的时候还是报错。
按照官方的解决方法,可以仿照类似的操作,在系统中新建一个配置类。用来在建表的时候将oid类型替换成postgres中的text类型。代码如下:

/**
* description: 
* @author litong
* @date 2023/9/19
*/
public class AdpPostgreSQLDialect extends PostgreSQL10Dialect {

    public AdpPostgreSQLDialect() {
        super();
        registerColumnType(Types.BLOB, "bytea");
        registerColumnType(Types.CLOB, "text");
    }

    @Override
    public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
        switch (sqlTypeDescriptor.getSqlType()) {
            case Types.CLOB:
                return LongVarcharTypeDescriptor.INSTANCE;
            case Types.BLOB:
                return LongVarbinaryTypeDescriptor.INSTANCE;
            case Types.NCLOB:
                return LongVarbinaryTypeDescriptor.INSTANCE;
        }
        return super.remapSqlTypeDescriptor(sqlTypeDescriptor);
    }
}

将这个类写进去之后,我们在application-product.properties配置文件中进行激活

spring.datasource.remote.hibernate.properties.hibernate.dialect=tech.powerjob.server.persistence.config.dialect.AdpPostgreSQLDialect

=号后面是你的类的全限定名,视个人情况改变。修改之后就可以正常使用powerjob-server来进行定时任务的调度了

猜你喜欢

转载自blog.csdn.net/Libigtong/article/details/133088772