Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Dali » Unable to get Entity back from database as the Entity object.(Data is returned as a java.lang.Object not my Entity object.)
Unable to get Entity back from database as the Entity object. [message #665241] Wed, 13 April 2011 20:28 Go to next message
ekim  is currently offline ekim Friend
Messages: 12
Registered: October 2009
Junior Member
So, I am up and running with Helios (for Java EE Developers) and trying to hit our databasae (Sybase) to retrieve data from some (any) table.

Also installed EclipseLink 2.0 (did I need this?)

I created a Java class to align with a DB table and added javax.persistence.* annotations, setter and getters and implemented Serializable.

I have test code that uses EntityManagerFactory to get an EntityManager that uses createNativeQuery(...).getResultList() and I do get a result list. However the result list contains Objects rather than my Entity objects. While debuging I can see the contents of the object but get a casting exception anytime I try to use the Object as an Entity.

I then found the "Entities From Tables" and re-generated my entity this way - essentially the same class but, still get the same Object result.
[Ljava.lang.Object; cannot be cast to com.jpa.test.ImagePerson
at com.jpa.test.Main.main(Main.java:29)

What am I missing, doing wrong or not doing?


-mike
Re: Unable to get Entity back from database as the Entity object. [message #665259 is a reply to message #665241] Wed, 13 April 2011 22:09 Go to previous messageGo to next message
Neil Hauge is currently offline Neil HaugeFriend
Messages: 475
Registered: July 2009
Senior Member
You don't need EclipseLink specifically, but you do need a JPA implementation, which EclipseLink provides.

Did you pass a resultClass parameter to createNativeQuery(...)? If not, this would explain why you got back objects instead of instances of your entity.

If you are getting started with JPA, I recommend picking up "Pro JPA 2" by Mike Keith and Merrick Schincariol.

Neil
Re: Unable to get Entity back from database as the Entity object. [message #665265 is a reply to message #665259] Wed, 13 April 2011 23:27 Go to previous messageGo to next message
ekim  is currently offline ekim Friend
Messages: 12
Registered: October 2009
Junior Member
I wondered if Dali was doing somthing that you once needed EclipseLink (or other, Hibernate, OpenLink, etc.) for - OK so that's not the issue.

Yes I passed a simple SQL "SELECT * FROM tableName" for the method call.

Thanks for the book recommendation, new to Web Services in general (not just JPA) - coming from core and OSGi programming.
Re: Unable to get Entity back from database as the Entity object. [message #665526 is a reply to message #665259] Thu, 14 April 2011 22:35 Go to previous message
ekim  is currently offline ekim Friend
Messages: 12
Registered: October 2009
Junior Member
So, after RTFM . . .

I was not using the EntityManager [em.createNativeQuery()] methods properly. It accepts native SQL or JPQL with/without the Entity class and when I understood the how and why it worked as expected.

Thanks again for the book recommendation.
Previous Topic:Unable to generate JAXB classes
Next Topic:provisional API changes
Goto Forum:
  


Current Time: Fri Apr 19 03:06:09 GMT 2024

Powered by FUDForum. Page generated in 0.02774 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top