繁体   English   中英

为什么在查询时即使参数是String,String也会被转换为Long

[英]Why String get converted to Long even when the parameter is String when querying

@Entity
@Getter
@Setter
@Table(name = "product_wallet")
@NamedQuery(name = "ProductWallet.findAll", query = "SELECT pw FROM ProductWallet pw")
@EntityListeners(CUEntityListener.class)
public class ProductWallet implements Serializable, CUEntity {

  private static final long serialVersionUID = 1L;
@Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = "product_wallet_id", unique = true, nullable = false)
  private Long productWalletId;

  @Column
  private Integer total;

  @Column
  private String status;

  @Column(name = "user_id", updatable = false, insertable = false)
  private String userId;

  @Column(name = "member_id", updatable = false, insertable = false)
  private Long memberId;

  @Column(name = "provider_id", updatable = false, insertable = false)
  private String providerId;

  @Column(name = "created_by", length = 100)
  private String createdBy;

  @Column(name = "created_date")
  private Timestamp createdDate;

  @Column(name = "modified_by", length = 50)
  private String modifiedBy;

  @Column(name = "modified_date")
  private Timestamp modifiedDate;

  //bi-directional many-to-one association to MUser
  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "user_id", referencedColumnName = "user_id")
  private MUser user;

  @OneToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "member_id")
  private Member member;

  @OneToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "provider_id")
  private Provider provider;

  @OneToMany(fetch = FetchType.LAZY, mappedBy = "productWallet")
  private List<ProductWalletItem> productWalletItems;

我正在尝试使用 JPA 的自动查询创建、手动编写查询等来使用此方法。

ProductWallet findProductWalletByProviderIdAndMemberId(String providerId, Long memberId);

但由于某种原因,所有字符串 providerId 都转换为 Long ,我收到此错误。 似乎 jdbc 正在拼命尝试将某些内容转换为 Long:

Bad value for type long : PR_0000000288
2019-10-11 19:12:56 - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute query; SQL [select productwal0_.product_wallet_id as product_1_41_, productwal0_.created_by as created_2_41_, productwal0_.created_date as created_3_41_, productwal0_.member_id as member_i4_41_, productwal0_.modified_by as modified5_41_, productwal0_.modified_date as modified6_41_, productwal0_.provider_id as provider7_41_, productwal0_.status as status8_41_, productwal0_.total as total9_41_, productwal0_.user_id as user_id10_41_ from product_wallet productwal0_ where productwal0_.provider_id=? and productwal0_.member_id=?]; nested exception is org.hibernate.exception.DataException: could not execute query] with root cause
org.postgresql.util.PSQLException: Bad value for type long : PR_0000000288
    at org.postgresql.jdbc.PgResultSet.toLong(PgResultSet.java:2860)
    at org.postgresql.jdbc.PgResultSet.getLong(PgResultSet.java:2114)
    at org.postgresql.jdbc.PgResultSet.getLong(PgResultSet.java:2506)
    at com.zaxxer.hikari.proxy.HikariResultSetProxy.getLong(HikariResultSetProxy.java)
    at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$2.doExtract(BigIntTypeDescriptor.java:63)
    at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47)

我认为这是因为您的表中有两个provider_id列。 一个用于归档的providerId ,另一个用于Provider object 的连接列。 我假设 object Provider的 id 是 Long 类型。 您可以重命名其中一个并尝试吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM