1

我在下面有一个实体类。重要的是,user_config 列保留了基于 JSON 的用户配置,因此我必须使用 @Lob 注释变量。

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long id;

  @Column(name = "user_name")
  @NotNull
  private String userName;

  @Lob
  @Column(name = "user_config")
  @NotNull
  private String userConfig;

我试图从下面的数据库中通过 JPA 存储库获取一堆条目:

@Repository
public interface UserConfigRepository extends CrudRepository<UserConfig, Long> {
  List<UserConfig> findByUserName(String userName);
}

最后,我在下面有一个例外:

Caused by: org.postgresql.util.PSQLException: Bad value for type long : "some user info"
    at org.postgresql.jdbc.PgResultSet.toLong(PgResultSet.java:2894)
    at org.postgresql.jdbc.PgResultSet.getLong(PgResultSet.java:2101)
    at org.postgresql.jdbc.PgResultSet.getClob(PgResultSet.java:447)
    at org.postgresql.jdbc.PgResultSet.getClob(PgResultSet.java:434)
    at com.zaxxer.hikari.pool.HikariProxyResultSet.getClob(HikariProxyResultSet.java)
    at org.hibernate.type.descriptor.sql.ClobTypeDescriptor$1.doExtract(ClobTypeDescriptor.java:44)
    at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:257)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:253)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:243)
    at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:329)
    at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:3087)
    at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1877)
    at org.hibernate.loader.Loader.hydrateEntityState(Loader.java:1805)
    at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1778)
    at org.hibernate.loader.Loader.getRow(Loader.java:1626)
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:743)
    at org.hibernate.loader.Loader.getRowsFromResultSet(Loader.java:1042)
    at org.hibernate.loader.Loader.processResultSet(Loader.java:993)
    at org.hibernate.loader.Loader.doQuery(Loader.java:962)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:352)
    at org.hibernate.loader.Loader.doList(Loader.java:2857)
    ... 102 more 

你能帮我解决这个错误吗?

PS:SpringBoot版本:2.3.2.RELEASE

4

0 回答 0