Seems like you ought to be able to model this in cayenne without too much difficulty.
Main Entity -> Map relationship of value entities. Each value entity has a to-one relationship to the attribute descriptor table.
One thing you might consider doing in your attribute descriptor table is to make the "type" be a java enum; then you can add types to the system as needed with whatever behavior you need for the type (eg: explicit knowledge of how to convert the database value/type to the application/logical value/type). Alternatively, I've used cayenne's ability to supply custom types/custom type converters successfully in the past to do/help with this sort of thing.
You could overwrite readProperty in a base Persistent object to check first if the property in question is one of the map properties; if so, read it instead, otherwise, pass handling back to cayenne. Same goes for write.
Something along those lines... it sounds like your use-case is probably simple enough that you could do this all with application-level code without having to hack cayenne.
Robert
On Aug 23, 2010, at 8/239:21 AM , Adrian Wiesmann wrote:
> Hi there
>
> Has anybody ever tried to implement the Entity Attribute Value (EAV) model [1] with the help of Cayenne.
>
> Or do you have another idea how to model fully typified additional fields to existing tables so that administrators can enhance their installation?
>
> The idea behind this is that some companies have - as example - different needs to describe their records or to group their assets. Now we could go the simple way and just add a few (varchar) fields in the table here and there. But these additional fields would neither be typified nor would they have sounding names but something like field1, field2. Chaos guaranteed :)
>
> Now I am looking for a way to allow an administrator to define which table may have what additional fields. He should be required to define the type, length.. of these additional fields. EAV sounds like the way to go, but I am not sure about extending Cayenne for this.
>
> Thanks for your input.
>
> Cheers,
> Adrian
>
> [1] http://en.wikipedia.org/wiki/Entity-attribute-value_model
This archive was generated by hypermail 2.0.0 : Mon Aug 23 2010 - 15:07:48 UTC