java - How to add property counted in DB to @Entity class? -


i have entity. , need object contains value, call 'depth'. query may 'select b.id, b.name, b..., count(c.id) depth entity b, centity c ...'. i've created class nonhibernateentity extends entity. , results of query written above stored list of nonhibentity, consists of fields of entity (as extended), , property 'depth'. make setting aliastobean results transformer: .setresulttransformer(transformers.aliastobean(nhentity.class)). but, annoying , inconvenient - specify aliases of needed fields. , then, if want save 1 of object db - session.saveorupdate((enity)nhibentity) - there exception nhibentity isn't hibernate entity.

i heard storing 'entity' field in nonhibentity (aggregation, not inheritance). seems rather inconvenient too. think? appropriate solution?

a formula column mapping may suitable needs. try first.

if causes performance issues fear, might try mapped class hierarchy field in child, , mapping both same table. not sure work though...

as last resort, you've got using non-mapped class, entity field in other class - aggregation instead of inheritance say, , make sure there's way of retrieving mapped entity unmapped 1 can save. sensible make decorator, it's both subclass , aggregate , can continue ignore distinction in of code.

with non-mapped subclass and/or aggregate, however, you'll have pull out entity in order save.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -