-->
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.  [ 2 posts ] 
Author Message
 Post subject: Storing additional information for an object
PostPosted: Wed Jul 26, 2006 10:20 pm 
Newbie

Joined: Wed Jul 26, 2006 9:53 pm
Posts: 16
For my application i need to store additional information about objects. this additional information is not part of the object properties. And using this additional information I want to filter the results using the Hibernate filters.

Say for example I have a class 'Fish' :

public class Fish {
int id;
String name;
String color;
}

and mapping is:
<class name="Fish" table="FISH" batch-size="10">
<id name="pid" type="long" column="PK_pid" access="property"/>
<property name="name" column="name" type="java.lang.String" access="property" not-null="true" unique="false"/>
<property name="color" column="color" type="java.lang.String" length="1024" access="property" not-null="false" unique="false"/>
</class>

Now along with this information for each fish object in my application i want to store the id for the user who created the object. But I do not want to model it as a property of the Fish class itself.
Is there a way for me to specify an extra column "owner" for the Fish table.
I want to be able to filter out the objects on the basis of this "owner" value and be able to also specify and persist the owner value at the time of save/update.
My filter definition is:
<filter-def name="ownerFilter">
<filter-param name="ownerFilterParam" type="string"/>
</filter-def>

And I want to be able to specify it for the Fish class as shown below:
<class name="Fish" table="FISH" batch-size="10">
<id name="pid" type="long" column="PK_pid" access="property"/>
<property name="name" column="name" type="java.lang.String" access="property" not-null="true" unique="false"/>
<property name="color" column="color" type="java.lang.String" length="1024" access="property" not-null="false" unique="false"/>

<filter name="ownerFilter" condition=":ownerFilterParam = owner"/>

</class>

Such that when this filter is enabled this for the session only fishes for a particular owner are retrieved.

Is it possible to specify additional columns for a table that are not part of the object mapped to that table?

I would highly appreciateI would really appreciate any information/links as to how this can be achieved.

Thank in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 28, 2006 9:35 pm 
Newbie

Joined: Wed Jul 26, 2006 9:53 pm
Posts: 16
I managed to solve my problem, by using custom property accessors.
Just posting teh summary of my solution incase someone else is facing the same issue.
I added a propety mapping in the hbm file even though there is no-such property for my object. And in this mapping I have specified custome property accessors. With the custome property accessors I can control what i set or give or from where I give the value.


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