Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPA with extended objects(Access only base class objects with EclipseLink)
JPA with extended objects [message #1043492] Wed, 17 April 2013 15:39 Go to next message
Neil Cohen is currently offline Neil Cohen
Messages: 7
Registered: June 2012
Junior Member
I have a database with a set of tables that have some foreign keys to relate objects in different tables. I was originally able to use JPA to access those objects. Now I am attempting to separate some user-level information into super-classes and have only the database information in the base classes. And now I can't seem to write my data back to the database.

Simple example -

public class Foo{
Integer id;
String name;

<getters and setters>
}

public class ExtendedFoo extends Foo{
int non_db_info = 0;

public routine_that_uses_non_db_info(){
}
}

My User level programs want to read and write Foo objects, but work with them as ExtendedFoo objects. Can someone tell me how to set up my EclipseLink environment to make this happen?

If I read a list of Foo objects into a JPA Container and try
addEntity(ExtendedFoo ef) I get an error that says there is no descriptor for the ExtendedFoo class - which is correct. Do I need to manually construct a parallel heirarchy of Foo objects before writing them back to the database?

The reason I'm doing this is that the extended objects include references to my Vaadin UI environment, and I don't want the database library to have to include Vaadin jar files...

Any help would be most appreciated

thanks,

nbc
Re: JPA with extended objects [message #1044094 is a reply to message #1043492] Thu, 18 April 2013 09:35 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1016
Registered: July 2009
Senior Member
So Foo is an entity and you can call persist on it? If that is the case, you should also be able to persist ExtendedFoo and other Foo subclasses. EclipseLink will go through ExtendedFoo's superclasses when looking for a descriptor to decide if it can be persisted as an entity. If this isn't working, it might be that the classloader loading ExtendedFoo is different than the one used within the persistence unit such that ExtendedFoo.getSuperclass() != Foo.

Best Regards,
Chris
Re: JPA with extended objects [message #1044182 is a reply to message #1044094] Thu, 18 April 2013 11:29 Go to previous message
Neil Cohen is currently offline Neil Cohen
Messages: 7
Registered: June 2012
Junior Member
Yes - Foo is an entity and persist does work on it. The member variables in ExtendedFoo are basically Transient variables - they are not needed in the database. I will check the getSuperClass() and see if the loader is doing something screwy.

Thanks for the help,

nbc
Previous Topic:Using CopyGroup and CASCADE_TREE depth always get a null as copied entity
Next Topic:xsi:type with namespace using MOXy
Goto Forum:
  


Current Time: Wed Jul 30 03:24:15 EDT 2014

Powered by FUDForum. Page generated in 0.01733 seconds