Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Mapping two objects on same table
Mapping two objects on same table [message #528692] Wed, 21 April 2010 09:52 Go to next message
Xavier Z is currently offline Xavier Z
Messages: 8
Registered: April 2010
Junior Member
Hello,

I m working on a legacy database. I m encountering the following problem, there is two classes mapped into a single table. The only way to differentiate them is their id.
The Id of each of thel belongs to two differents sequences.

Example :

create table Objet ( ID number (10), value varchar2(50), value2 varchar2(50) );

create sequence seq1 start with 1 increment by 1 maxvalue 199;

create sequence seq2 start with 200 increment by 1 maxvalue 299;

I have two classes one corresponding to the value of the first sequence and the other to second one. these two classes do not belong to same hierarchy

I m using JPA 1.0 based on eclipselink 1.0.2.

I can not find a way to do this, can you help me?

X

[Updated on: Wed, 21 April 2010 09:54]

Report message to a moderator

Re: Mapping two objects on same table [message #528939 is a reply to message #528692] Thu, 22 April 2010 09:18 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

I very odd design. You might consider having one class, or two tables.

You could map this in EclipseLink. You could set an additionalJoinExpression on the two classes where the id < 200, and id >= 200. You would need to do this in code, using a DescriptorCustomizer.

public void customize(ClassDescriptor descriptor) {
descriptor.getQueryManager().setAdditionalJoinExpression(... );
}


James : Wiki : Book : Blog : Twitter
Re: Mapping two objects on same table [message #531050 is a reply to message #528692] Mon, 03 May 2010 10:08 Go to previous messageGo to next message
Xavier Z is currently offline Xavier Z
Messages: 8
Registered: April 2010
Junior Member
is it so weird ? Laughing
Re: Mapping two objects on same table [message #531061 is a reply to message #528939] Mon, 03 May 2010 10:40 Go to previous messageGo to next message
Xavier Z is currently offline Xavier Z
Messages: 8
Registered: April 2010
Junior Member
I ve already tried this but it doesn't work for basic operation. Eclipselink doesn't add the addionnal join. I did not forget to add the @Customizer annotation to the class.
Do you have any idea ?


Re: Mapping two objects on same table [message #531073 is a reply to message #528692] Mon, 03 May 2010 11:32 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

The additionalJoinExpression will be added to any query operation.


James : Wiki : Book : Blog : Twitter
Re: Mapping two objects on same table [message #531800 is a reply to message #531073] Thu, 06 May 2010 05:11 Go to previous message
Xavier Z is currently offline Xavier Z
Messages: 8
Registered: April 2010
Junior Member
Cool it's working, thanks a lot for your help.
Previous Topic:JPA entities returned from WebService
Next Topic:JPA Questions
Goto Forum:
  


Current Time: Tue Jul 22 11:45:31 EDT 2014

Powered by FUDForum. Page generated in 0.02452 seconds