Get your CodeRanch badge!*
The moose likes Object Relational Mapping and the fly likes Getting record to be updated in JPA. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Getting record to be updated in JPA." Watch "Getting record to be updated in JPA." New topic
Author

Getting record to be updated in JPA.

victor chiong
Ranch Hand

Joined: Apr 04, 2012
Posts: 73
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

Joined: Oct 16, 2003
Posts: 1075
    
  10

Hi,
Please UseCodeTags when posting code. You have mentioned error, but you have not told us what the error is. Please TellTheDetails.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
victor chiong
Ranch Hand

Joined: Apr 04, 2012
Posts: 73
I want to retrieve a record from my table... I could not understand why the error happend....
victor chiong
Ranch Hand

Joined: Apr 04, 2012
Posts: 73
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

Joined: Apr 04, 2012
Posts: 73
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

Joined: Mar 07, 2010
Posts: 1632
    
    7

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


[How To Ask Questions][Read before you PM me]
victor chiong
Ranch Hand

Joined: Apr 04, 2012
Posts: 73
Thanks

I will remember that toString() and the L
 
Don't get me started about those stupid light bulbs.
 
subject: Getting record to be updated in JPA.
 
Similar Threads
Urlybird 1.1.1
JPA, EJB and Web Application
Merge detached sub-class entity (JPA InheritanceType.SINGLE_TABLE) org.hibernate.WrongClassException
JPA with JSF
JPA Unidirectional 1to1 mapping issue: A Foreign key has the wrong number of column. should be 2