-->
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.  [ 5 posts ] 
Author Message
 Post subject: Mapping component - defining one time
PostPosted: Thu Sep 03, 2009 8:12 pm 
Newbie

Joined: Wed Oct 22, 2003 2:43 pm
Posts: 7
I have a BaseObject that all other domain objects extend. It contains properties like:

id
name
description
createdOn
createdBy
modifiedOn
modifiedBy

How can I define this only 1 time in my .hbm file and reuse this over and over? I've read the documentation on defining components, but I don't want to repeat the xml for every persisted object. Can someone point me to a solution?

Thanks.


Top
 Profile  
 
 Post subject: Re: Mapping component - defining one time
PostPosted: Sun Sep 06, 2009 7:40 am 
Newbie

Joined: Wed Oct 22, 2003 2:43 pm
Posts: 7
Just to be more clear on what I'm looking for, as I'm sure there's a way to do this:

I have an object called document which I map as follows:

Code:
    <class name="Document" table="document">
        <id column="id" name="id" unsaved-value="null">
            <generator class="identity"/>
        </id>
         ...
         ...
        <component class="AuditInformation" name="AuditInformation">
            <property column="created_on" name="createdOn" type="timestamp"/>
            <property column="created_by" name="createdBy"/>
            <property column="last_modified_on" name="lastModifiedOn" type="timestamp"/>
            <property column="last_modified_by" name="lastModifiedBy"/>
        </component>
   </class>


This 'AuditInformation' component is used on virtually all of my objects. These 4 columns are on every table and I define them once in a BaseObject that all others inherit. I hate to repeat this information in each .hbm definition if that's not necessary.

Can someone point me in the right direction?

Thanks,
Mike


Top
 Profile  
 
 Post subject: Re: Mapping component - defining one time
PostPosted: Sun Sep 06, 2009 1:23 pm 
Beginner
Beginner

Joined: Fri Oct 28, 2005 10:46 am
Posts: 37
It seems that your problem is that you're using your BaseObject to avoid code duplication, and now you're seeing the duplication problem in your mappings. Why not map it the same way that you've written the classes? Map BaseObject with the AuditInformation component and then map Document and the rest of your classes as subclasses of it. I think you could get what you're looking for with the table-per-concrete-class strategy as described here:
http://docs.jboss.org/hibernate/stable/ ... erconcrete


Top
 Profile  
 
 Post subject: Re: Mapping component - defining one time
PostPosted: Mon Sep 07, 2009 9:11 pm 
Newbie

Joined: Wed Oct 22, 2003 2:43 pm
Posts: 7
This will work... I started down this path but abandoned it for some reason. As a I re-read it it's exactly what I need. Thanks.


Top
 Profile  
 
 Post subject: Re: Mapping component - defining one time
PostPosted: Mon Sep 07, 2009 10:03 pm 
Newbie

Joined: Mon Sep 07, 2009 9:56 pm
Posts: 4
I would suggest looking at the example Audit Logging with the Hibernate Interceptor this approach puts all the audit information for all your tables is in one or two tables which is easier to query by user/date/type etc, and you won't have the duplicated definitions.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.