0
@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; 

I am trying to use this method using the automatic query creation by JPA, writing the query manually, etc.

ProductWallet findProductWalletByProviderIdAndMemberId(String providerId, Long memberId); 

but for some reason, String providerId get converted to Long for all of them and I get this error. It seems like jdbc is desperately trying to convert something to 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) 
5
  • Do you have access to database? It seems there is a "PR_0000000288" in your table? Commented Oct 11, 2019 at 23:30
  • @aksappy I do have access to the DB and provider_id is "PR_0000000288" and that column datatype is varchar(100) Commented Oct 11, 2019 at 23:32
  • What is the Id for Member class? Commented Oct 11, 2019 at 23:38
  • @aksappy memberId for this row is 18468 which is bigInt. I run the query in the DB it works fine but not with jpa Commented Oct 11, 2019 at 23:40
  • Kindly share the Provider entity class too as it looks like you have the Id field in the Provider class as Long and the ProductWallet has a providerId as String. Hence the former is taken in the query and so the error. Commented Oct 12, 2019 at 7:04

1 Answer 1

3

I think it's because you have two provider_id column in your table. One for the filed providerId and the other for the join column for Provider object. I assume the id for the object Provider is Long type. Can you rename one of these and try?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.