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.  [ 4 posts ] 
Author Message
 Post subject: Mapping columns without properties
PostPosted: Wed Jul 26, 2006 2:37 am 
Newbie

Joined: Fri Jan 06, 2006 12:10 am
Posts: 7
I have a number of cases where columns exist solely for operational purposes (purging, partitioning, data warehouse reporting). I'd like a way to populate these values even though the object model does not contain them.

As an example, say every table has a column called PARTITION_ID. The partition id does not exist in the object model, but can either be derived from some properties on the object model, grabbed from some thread local session information, or calculated from some static method. Basically, it should be some logic that can be placed into a UserType. I have experimented with a few different ways of doing this:

dynamic-map entity-mode:
Using this entity mode I am able to get the flexibility I need, but it comes at the cost of having to turn large object hierarchies into a large map of maps. Also, where it is only a table or two that has columns like this, I am forced to use this entity-mode for all of my objects.

dynamic-components:
If I added a map to every object, this would work great. Unfortunately, at that point I might as weel just add the columns I wanted then :) Of course, if I could somehow make a map available on all object via a proxy, there might be some way to work with this.

custom user types:
This is where I have had the most success, but I've had to really hack things up. Basically by creating a CompositeUserType I can map a property that does exist on the object to two columns, one which is the proper column for the property and one which holds this additional unrelated data:

<property name="description">
<column name="DESCRIPTION"/>
<column name="PARTITION_ID"/>
<type name="PartitionHackType">
<param name="typeName">string</param>
</type>
</property>

where the "typeName" param is simply the name of a Type I can retrieve by calling TypeFactory.basic().

Of course, this is just a hack.

I've discussed using triggers with the DBAs, but they are unhappy with the associated performance issues and additional maintenance. Using a combination of the oracle context (basically just a session hashmap), event listeners, and default values coming from the context, I have a possible solution but it has more moving parts than I am comfortable with. In the end, the DBAs don't understand why I'm having any difficulty at all with these columns and feel it must be a limitation in hibernate (which in some ways it appears to be).

In my ideal world, I would just be able to say something like:
<property name="partitionId" db-only="true">
<column name="PARTITION_ID"/>
<type name="PartitionType"/>
</property>
or
<column name="PARTITION_ID" type="PartitionType"/>

The first case seems like it would be easier to fit into the current architecture (at least from the few times I have actually looked deep into the bowels of hibernate), but the second option seems much more explicit (I guess it might just be syntactic sugar).

I'm open to any suggestions others might have on how I might do this without any changes to hibernate, but I'd also like to hear what the chances of getting something like this into hibernate are (either by coding it myself or asking for a new feature in jira).


Top
 Profile  
 
 Post subject: Bump
PostPosted: Fri Aug 18, 2006 4:36 am 
Newbie

Joined: Fri Jan 06, 2006 12:10 am
Posts: 7
Does anyone have any thoughts on this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 4:48 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
You could use <sql-insert>.


Top
 Profile  
 
 Post subject: access="noop"
PostPosted: Mon Aug 21, 2006 9:38 pm 
Newbie

Joined: Fri Jan 06, 2006 12:10 am
Posts: 7
Courtesy of Max, the answer is simply to use access="noop":

<property name="partitionId" access="noop" column="PARTITION_ID" type="PartitionType"/>

So once again I find that Hibernate already supports the feature I need...


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

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.