How to map an association with an Enum [message #530788] |
Fri, 30 April 2010 18:15  |
Eclipse User |
|
|
|
Using EclipseLink 2.0.1, JDK 6
I have a challenging situation that I have inherited. Currently this is being done with Hibernate but I've gotten the approval to migrate over to EclipseLink.
I have a table, Address
CREATE
TABLE Address
(
AddressID ID NOT NULL IDENTITY
, ... some more fields
, AddressTypeID INT
)
And table AddressType
CREATE
TABLE AddressType
(
id NOT NULL int
, name varchar(30)
, ref varchar(30)
, isActive bit
)
The challenge I am faced with is that the AddressType table is actually a view. The id field is the actual primary key in the table that the view is build upon. The ref field is a String which represents the actual type of data the view represents (Billing,Shipping,US,CustomerService,etc..). When an association is made to the Address table the AddressType.id is stored on the Address record.
What I would like to do is have a single enum class, AddressType, that represents the String values only and have a reference to the enum on the Address class. But how can I ensure during insert/update operations that the actual ID of the AddressType gets persisted? In addition, how can I map that ID from the Address table to the enum during a read operation?
All suggestions are welcome.
Thanks...
|
|
|
|
|
Re: How to map an association with an Enum [message #531175 is a reply to message #531126] |
Tue, 04 May 2010 01:19  |
Eclipse User |
|
|
|
> Normally this
> would be trivial but I can't figure out an easy way to gain access to
> the EntityManager from within a mapping class.
For my projects I also wanted any entity to be able to access an EntityManager in order to add or modify other entities. So I introduced the concept of EntityManagerFinder.
You can do a EntityManagerFinder.find() and it will return the correct EM. The EMF can either find the EM by GUI component (one EM per JFrame for fat clients) or by thread (for webapplications). Naturally somewhere there is code binding an EM to these, e.g. in a webapp there is a filter that allocates an EM and binds it to the thread being assigned to process the request.
That might solve this problem.
|
|
|
Powered by
FUDForum. Page generated in 0.09213 seconds