views:

25

answers:

1

Hi,

I'm extending the data model of an Java application to include some kind of a setting facility. Settings in this application would basically be Strings or Numbers, no entities or other model objects.

My Question is what's the best way to map this requirement to JPA (Hibernate)?

I first thought about implementing a Setting class with properties for each desired type but maybe there is a way to use something like Hibernate's Any mapping? The Problem with the any mapping seems to be that it is meant to express relations to entities not embeddables.

Any ideas?

edit:

To clarify the requirement. I want to persist variable data in a simple way, think about C style union or a bean property of the Object type.

+1  A: 

Does JPA support a kind of “Any” mapping for embeddable objects?

To my knowledge, neither JPA nor Hibernate do support defining relation to embeddable which are not entities. Just in case, the JPA wikibook has a very interesting section on embeddables.

If I misunderstood your question, please clarify (again), your goal is still not clear (at least for me). Maybe a "pseudo" example could help.

Pascal Thivent
Thank you for pointing me to the JPA wikibook. The section on [Variable and Heterogeneous Relationships](http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Variable_and_Heterogeneous_Relationships) did clarify that JPA does not support the kind of mapping I want but suggests that some JPA implementations may support something alike.
itti