History | Log In     View a printable version of the current page. Get help!  
Issue Details [XML]

Key: EJB-104
Type: Improvement Improvement
Status: Open Open
Priority: Minor Minor
Assignee: Vance Karimi
Reporter: Olivier THIERRY
Votes: (View)
Watchers: (View)
Operations

If you were logged in you would be able to see more operations.
EJB Cartridge

Improve the way enumerations are managed in EJB3 cartridge

Created: 10/Apr/08 04:58 PM   Updated: 20/Jun/08 12:13 PM
Component/s: None
Affects Version/s: None
Fix Version/s: None

File Attachments: 1. XML File EJB3MergeMappings.xml (1 kb)
2. File EntityEmbeddable.vsl (43 kb)
3. File EntityEmbeddable.vsl.diff (2 kb)
4. File Enumeration.vsl (3 kb)
5. File Enumeration.vsl.diff (3 kb)
6. File GenericEnumUserType.vsl (5 kb)
7. File cartridge.xml.diff (1 kb)
8. File enumeration.vsl.fromMemberVariable.diff (1 kb)

Environment: AndroMDA 3.3-SNAPSHOT + EJB3 cartridge + Hibernate


 Description   
The way enum are generated, you have no way to set a value to be stored in database for enumeration literals. It will either be the name of the literal, or its order in the enumeration, depending on the value of @andromda.persistence.enumeration.type tagged value for entitty attributes having the enumeration as type. I used to use Hibernate cartridge before using EJB3 one, and you had the ability to set your own value for enumeration literals. It could be very important if you work on an application with existing datas !

More details on the forum : http://galaxy.andromda.org/forum/viewtopic.php?t=5650

 All   Comments   Change History      Sort Order:
Comment by Olivier THIERRY [10/Apr/08 05:08 PM]
These files implement a solution I found on this link :
http://appfuse.org/display/APF/Java+5+Enums+Persistence+with+Hibernate

It uses @Type Hibernate annotation to define the mapping between enumeration and database. Note it is a Hibernate specific solution, as it looks there is no equivalent feature in JPA for the moment (and I hope there will be the equivalent in the future !).

Note thes files are not a patch to EJB3 cartridge but just templates I use with merge location features of AndroMDA.
You have to add these properties to EJB3 namespace in andromda.xml :
<property name="mergeLocation">${conf.dir}/cartridge/ejb3/custom</property>
<property name="mergeMappingsUri">file:${conf.dir}/mappings/EJB3MergeMappings.xml</property>

Then copy :
- templates to "/mda/src/main/config/cartridge/ejb3/custom/templates/ejb3" directory
- EJB3MergeMappings.xml file to "/mda/src/main/config/mappings" directory

Comment by Olivier THIERRY [18/Apr/08 03:58 PM]
As suggested by Vance on the forum, I added a test on $hibernateExtensionEnabled, so that this feature is enabled only if Hibernate is enabled.

GenericEnumUserType.vsl is the same as posted earlier.
Other templates + cartridge.xml file are supplied as diff files.

Comment by Olivier THIERRY [20/Jun/08 12:12 PM]
Added a from method to look for enumeration literal having a given value for a member variable. This method is generated only if member variable attribute has <<Identifier>> stereotype.
More details here : http://galaxy.andromda.org/forum/viewtopic.php?p=26077#26077

Comment by Olivier THIERRY [20/Jun/08 12:13 PM]
Sorry ... Forgot to say the patch was in enumeration.vsl.fromMemberVariable.diff attached file.