Add support for exposing unmapped attributes in a generic manner

Description

When working with OGM an existing database, it would be very useful to allow to propagate any unmapped attributes of a record/document in a generic container.

Taking a web shop with a Product entity as example, you typically don't need to (or even can) "know" all the attributes of such a product entity but still want to be able to display all the attributes in a generic fashion e.g. on a web page. Only a few attributes actually need to be known/mapped in the application itself, namely those fields to which specific handling/logic applies.

To facilitate such a scenario, one could designate a Map property of an entity to hold any unmapped attribute.

Considering e.g. the following MongoDB document:

This could be mapped to a Product entity like this:

While the attributes common to every product document are explicitly mapped as properties, all unmapped properties are exposed via the additionalProperties map which is designated for that purpose using a new annotation, e.g. named @AdditionalProperties. The application can perform logic on the common known attributes and still forward all unmapped attributes to a generic web view etc.The types of the map values would be those returned from the underlying store.

Such a facility would also help with prototype development, where one starts with most attributes not being explicitly mapped and then creates specific members iteratively as application requirements demand.

Also the CouchDB dialect would benefit from this, because it doesn't support partial updates at the moment, meaning one currently must map all attributes or an update (which always writes back a complete document) may discard any unmapped attributes.

Environment

None

Activity

Show:
Gunnar Morling
February 26, 2014, 10:02 AM

Ah, do you have a pointer to that functionality in ORM (e.g. ref guide)?

Gunnar Morling
February 26, 2014, 1:40 PM

I had looked at ORM Dynamic Models at some point, but they don't seem to fully cover what I have in mind.

This is more about the case where you don't know all attributes in advance and still want to pass them through in a generic fashion which I think is a common case in NoSQL, if not the primary motivation for using a schema-free store. Also I'm interested in the combination of fixed and unmapped attributes which I don't think is possible with Dynamic Models.

Emmanuel Bernard
February 26, 2014, 2:11 PM

yes that's what I said basically But I suspect you will need to update ORM's engine to pass along the extra data.

darren hartford
December 18, 2014, 1:36 PM
Edited

forum reference: https://forum.hibernate.org/viewtopic.php?f=31&t=1037517&p=2482188

Some options around query/search/sort options either in JPA-QL or other approaches would be good.

If this is portable to a traditional database structure (i.e. a JPA entity with the @AdditionalProperties annotation turns from OGM back to regular hibernate/JPA), even if not that performant, would also be great from a portability point-of-view (even if that mandates everything-is-a-string or other single type when using additionalproperties)

"don't know all attributes in advance and still want to pass them through in a generic fashion" - yes, and while working through it during runtime to be able to define on-the-fly then allow search/sorting on those additional properties. Setting expectations that this would/should be less performant than fully define fields, but at least this is something versus nothing.

Assignee

Unassigned

Reporter

Gunnar Morling

Labels

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Components

Fix versions

Priority

Minor
Configure