[英]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.