Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Mapping a lookup table
Mapping a lookup table [message #382534] Thu, 16 October 2008 14:29 Go to next message
Rama Notowidigdo is currently offline Rama Notowidigdo
Messages: 19
Registered: July 2009
Junior Member
Hi All,

What's the best way to map a lookup table in EclipseLink JPA?
It's very easy to do in toplink but not sure if it is availabe in JPA.

An example of lookup table;

Postal Code with (id, value) .. [(1,94543), (2,94127)...]
I don't want to create a separate object for the Postal Code.

Thanks.

Cheers,
rgn
Re: Mapping a lookup table [message #382536 is a reply to message #382534] Thu, 16 October 2008 21:13 Go to previous messageGo to next message
Doug Clarke is currently offline Doug Clarke
Messages: 155
Registered: July 2009
Senior Member
Rama,

Anything you could map with TopLink you should be able to map with
EclipseLink although some mappings may exceed the JPA 1.0 specification. I
am not sure exactly how you want to map this so if you could provide more
details I am sure we can help.

Doug
Re: Mapping a lookup table [message #382538 is a reply to message #382536] Thu, 16 October 2008 23:21 Go to previous messageGo to next message
Rama Notowidigdo is currently offline Rama Notowidigdo
Messages: 19
Registered: July 2009
Junior Member
Thanks Doug. Basically I'm trying to do "Direct Collection" mapping. I
know can do this with EclipseLink but I'm having a hard time trying to do
this with JPA. What do I do in orm.xml?

Here is the data model:

Profile
--------
id
username,
gender
profile_status_id
...


Profile Status
-------------
id,
name


So on the object side, I don't want to have to create profile Status
object.
My object would look like:

Profile {

int id;
string userName;
string profileStatus;
}

How do I accomplish this with JPA? Is there way to leverage non supported
jpa mapping? If so I'd love to learn about it

Thanks in advance.

Cheers,
rgn
Re: Mapping a lookup table [message #382542 is a reply to message #382538] Fri, 17 October 2008 07:05 Go to previous messageGo to next message
Doug Clarke is currently offline Doug Clarke
Messages: 155
Registered: July 2009
Senior Member
EclipseLink offers @BasicCollection and @BasicMap annotations to configure
these mappings. They are not part of the JPA 1.0 spec (JPA 2.0 will
support this type of mapping).

http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#How_to_Use_the_.40BasicCollection_Annotation

If you want configure these advanced mappings in XML you can use an
eclipselink-orm.xml file (instead of the JPA standard one) and leverage
these advanced mappings as well. In the following example the Employee
class uses a BasicCollection mapping.

http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/tr unk/examples/org.eclipse.persistence.example.jpa.employee.xm l/src/META-INF/orm.xml


Doug
Re: Mapping a lookup table [message #382742 is a reply to message #382542] Fri, 17 October 2008 13:36 Go to previous messageGo to next message
Rama Notowidigdo is currently offline Rama Notowidigdo
Messages: 19
Registered: July 2009
Junior Member
Thanks Doug. On another note, In Eclipselink 1.0.1 for JPA. Does the
annotation work? I have to use the orm.xml, every time I put annotation
in the code it doesn't seem to work but it works fine with orm.xml? Is
there another setting to say use annotation instead of xml (like in spring
framework)?
Re: Mapping a lookup table [message #382743 is a reply to message #382742] Fri, 17 October 2008 14:52 Go to previous message
Doug Clarke is currently offline Doug Clarke
Messages: 155
Registered: July 2009
Senior Member
Rama,

I use annotations all the time and have also been mixing in orm.xml and
eclipselink-orm.xml to override the annotations. Is there any chance you
have configured your orm.xml to be metadata complete?

Does it ignore the annotations when you have no orm.xml at all?

Doug
Previous Topic:self referencing entiy
Next Topic:Test works under JTA but not JPA transactions
Goto Forum:
  


Current Time: Fri Aug 01 22:36:35 EDT 2014

Powered by FUDForum. Page generated in 0.08618 seconds