-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Extending an entity at runtime
PostPosted: Mon Jul 20, 2009 5:08 am 
Newbie

Joined: Mon Jul 20, 2009 4:41 am
Posts: 1
Hi Experts,

I need to extend entities at runtime by adding additional columns/properties to some of the instances. Take for example the Transaction entity given below:

Code:
Transaction:
  - Type
  - Date
  - Amount


I might want to add a "Discount" column/property to all Transaction instances. This should be configured at runtime by the business client, and I've come up with different ways of possibly doing this.

The first method uses additional tables such as these:

Code:
Transaction extends ExtendableEntity

ExtensionDefinition:
  - EntityName
  - ExtensionName
  - ExtensionType

ExtensionEntry:
  - ExtensionDefinition (FK)
  - ExtendableEntity (FK)
  - Value


Because I want these Extensions to be available to quite a number of Entities I introduce the ExtendableEntity super class, which allows ExtensionEntry to contain a reference to any of the Entities that can be extended. With this method the column/property definition will be contained in ExtensionDefinition, and the actual value, one for each instance, in ExtensionEntry.

The alternative is to add a CLOB to ExtendableEntity which contains the additional columns/properties values in XML format, and to create a custom UserType for this CLOB:

Code:
Transaction extends ExtendableEntity

ExtendableEntity:
  - CLOB

ExtensionDefinition:
  - EntityName
  - ExtensionName
  - ExtensionType


The data contained in the CLOB will then look something like this:

Code:
<extensions>
  <extension>
    <id>12</id>
    <value>Something</value>
  </extension>
</extensions>


I still need the ExtensionDefinition Entity in order to define the additional columns/properties.

Between these two options, which would you recommend and why?

Also, I have one additional unresolved issue. I'd like to load the ExtensionDefinitions of an Entity whenever it is loaded, but there is no foreign key association between ExtensionDefinitions and ExtendableEntities, as the ExtensionDefinitions apply to the Entity itself rather than its instances. In other words, I want to perform a query such as this:

Code:
Select * from ExtensionDefinition where EntityName = '<insert Entity class name here>'


I was hoping that, although I can do that manually when loading Entities, Hibernate could help me with loading those values automatically so that fetching through association might work correctly (i.o.w something like EntityA.getEntityB().getExtensionDefinitions()).

Any and all advice will be appreciated.
Thank you,
Jaco


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.