Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » [JPA-Newbie] -- JPA 2 for dynamic/custom entity types (database schemas)? (JPA2 and dynamic/custom types/schemas)
icon5.gif  [JPA-Newbie] -- JPA 2 for dynamic/custom entity types (database schemas)? [message #657000] Tue, 01 March 2011 10:33 Go to next message
Sebastien Chevalier is currently offline Sebastien ChevalierFriend
Messages: 6
Registered: March 2011
Junior Member
Dear EclipseLink forum members:

Still being new to JPA and having worked through the JPA2 spec as well as the corresponding Apress book for learning the underlying concepts, I am currently wondering if my current, rather dynamic application scenario can be realized in JPA2 in an easy way.

The simplified app scenario is like the following:
Suppose there should be a JEE6 web app that allows endusers to publish articles. There is a generic "Article" type with some common/default attributes such as

- author : String
- pubDatetime : String or own.DateTime
- title, subtitle, articleText : String
- ...

Additionally, a privileged group of endusers should be able to enhance this generic "Article" type by custom attributes during runtime (i.e., dynamically) and via a web interface. Additional attributes could be

- articleTopic : ArticleCategoryEnum
- rating : Float
- comments : List<String>
- ...

I guess the intention should be obvious and btw. not uncommon.

My remaining question basically is:

1. Is (EclipseLink) JPA 2 good for realizing such a dynamic scenario? If so, how could this be fulfilled in JPA 2 the best way.

2. In the contrary case, what alternative technologies would be a good practice for solving this dynamic problem?

Due to the topic's importance for me, I'd be very grateful for any help or other productive tips/hints.
Thank you very much in advance.

- Sebastien

Re: [JPA-Newbie] -- JPA 2 for dynamic/custom entity types (database schemas)? [message #657105 is a reply to message #657000] Tue, 01 March 2011 15:40 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

The simplest solution to adding dynamic attributes at runtime is for your Entity to have a Map of property objects. This could be mapped either as a ElementCollection, or a OneToMany to a Property Entity that has a name and value.


James : Wiki : Book : Blog : Twitter
Re: [JPA-Newbie] -- JPA 2 for dynamic/custom entity types (database schemas)? [message #657292 is a reply to message #657105] Wed, 02 March 2011 10:55 Go to previous messageGo to next message
Sebastien Chevalier is currently offline Sebastien ChevalierFriend
Messages: 6
Registered: March 2011
Junior Member
Dear James:

first of all, thank you very much for your hint.

Yes, *Maps* were one of the two general (i.e., not JPA specific) possibilities I could imagine before. For JPA, as I guess that it will be "hard" to create dyn. db schemas and maintain their evolution, I think the Map-based solution will be the best for me.

If I got it right, a "basic" Map-based solution storing String-based attribute value representations don't guarantee type maintenance and type safety, does it?

How could a Map-based solution be realized that distinguishes the several atomic and composed attribute types ('composed' in the sense of collection types consisting of (a) collection kind (array, list, set, probably map) and (b) element type (e.g. List<Person>))???

Thank you (all) very much for any further hints or mapping examples.

Best regards
- Sebastien
Re: [JPA-Newbie] -- JPA 2 for dynamic/custom entity types (database schemas)? [message #657378 is a reply to message #657000] Wed, 02 March 2011 15:55 Go to previous messageGo to next message
Doug Clarke is currently offline Doug ClarkeFriend
Messages: 155
Registered: July 2009
Senior Member
We are adding formal support for Extensible entities in EclipseLink Indigo (2.3).

http://wiki.eclipse.org/EclipseLink/DesignDocs/Extensibility

If you are interested in using this support with EclipseLink 2.2 I have started working on an example. The wiki page I just started to explain the example is available:

http://wiki.eclipse.org/EclipseLink/Examples/JPA/Extensible

Doug
Re: [JPA-Newbie] -- JPA 2 for dynamic/custom entity types (database schemas)? [message #657574 is a reply to message #657378] Thu, 03 March 2011 10:39 Go to previous messageGo to next message
Sebastien Chevalier is currently offline Sebastien ChevalierFriend
Messages: 6
Registered: March 2011
Junior Member
Hi Doug:

Thank you very much for these excellent links. The treated issues are exactly those I was looking for.

One question concerning the 'Extensible Entities Example' in EclipseLink 2.2.:
Do you already support multi-valued types for the dyn. attributes?
-- E.g., 'myEmployees' --> Array<Employee> or List<Employee> (Employee also including the user-enhanced props (accessible via the empID)).

If this is the case, how can these multi-valued props be specified?

Thanx a lot, again.
- Sebastien
Re: [JPA-Newbie] -- JPA 2 for dynamic/custom entity types (database schemas)? [message #657604 is a reply to message #657574] Thu, 03 March 2011 13:06 Go to previous message
Doug Clarke is currently offline Doug ClarkeFriend
Messages: 155
Registered: July 2009
Senior Member
Sebastien,

I do not have 1:M mapping (Collection<Employee>) support setup in the example yet but do plan to. Assuming the relationships are always classic FK on the target table and no additional join tables are required I believe it will be straight forward.

Doug
Previous Topic:SessionCustomizer in OSGi environments
Next Topic:generate entity classes from DB with TableGenerator
Goto Forum:
  


Current Time: Wed Apr 24 15:47:38 GMT 2024

Powered by FUDForum. Page generated in 0.02941 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top