• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting record to be updated in JPA.

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)


 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;

 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks

I will remember that toString() and the L
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic