Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting record to be updated in JPA.

 
victor chiong
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I am new to JPA and I could not understand why this in error. What I did in this could is to select the record to be updated but error happends.. Any ideas? I just one to update the record to be selected in customer entity.... thanks..

Error is:
Exception in thread "main" java.lang.IllegalArgumentException: You have provided an instance of an incorrect PK class for this find operation. Class expected : class java.lang.Long, Class received : class java.lang.Integer.
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.findInternal(EntityManagerImpl.java:729)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.find(EntityManagerImpl.java:653)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.find(EntityManagerImpl.java:532)
at com.main.Update.main(Update.java:24)


 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Please UseCodeTags when posting code. You have mentioned error, but you have not told us what the error is. Please TellTheDetails.
 
victor chiong
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to retrieve a record from my table... I could not understand why the error happend....
 
victor chiong
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

instead of 1 on the find() i declare long x = 1;



however the output is customer@12334r123; Why it is an address? I want the whole record of my table on the first row..... maybe you can advice me on something? I just follow the sample on code B.

# FIRST_NAME
1 Charles Dickens 10 Downing Street 1 NewYork 12345 RETAIL 2012-09-20 16:07:48.214
51 Charles Dickens 10 Downing Street 1 NewYork 12345 RETAIL 2012-09-20 16:21:18.324
101 victor Dickens 10 Downing Street 1 NewYork 12345 RETAIL 2012-09-21 13:54:35.962
151 Luchir Dickens 10 Downing Street 1 NewYork 12345 RETAIL 2012-09-21 13:54:52.754


Code B:

 
victor chiong
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I got it finally... hehehe..

em.find(Customer.class,x);

where x = a long integer and the index of the table...



If i want to retreive record with first name Victor, i just have to change x to 101. Luchir to x = 151;

 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FYI instead of doing this




you can just do this



Also remember if you want to print out an object in a human readable format you should override toString()

Glad you got it figured out
 
victor chiong
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks

I will remember that toString() and the L
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic