-->
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.  [ 9 posts ] 
Author Message
 Post subject: Include values in INSERTs/UPDATEs for non-class properties?
PostPosted: Tue Nov 18, 2003 2:19 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 7:53 pm
Posts: 66
Location: Lakeland, Florida USA
How to include values in INSERT/UPDATE ops that don't have property homes (Or, does my object model have to reflect my data model?)?

Bare with me here. I'm going to try to explain the "real" example by describing a trivial example. The "real" example is conceptually the same but much harder to describe.

Trivial example:

My keeps track of bid competitors - name, notes, competitiveness (high, medium, low) and if they won the bid or not. A simple object model might be defined as follows (see below, not showing bid). Below the 3 classes of the obj model are the relevant db tables that have been set up by the DBA. Note that both competitiveness (high, low, medium) and competitors are persisted in the REF_DATA_LIST and REF_DATA tables.

How could the mapping be done for the object model? (Assuming, of course that you think I have the right object model.)

Options I see for Competitor:

a) create an updatable view with "select * from REF_DATA_LIST list, REF_DATA data where list.TBL_SKEY = data.TBL_SKEY and list.TBL_NAME = 'COMPETITOR' "
b) use the "where" attribute of the class element

Both options would enable the creation, deletion & modification of the REF_DATA table. But what about LST_UPD_DATE & LST_UPD_USERID? They are not included as properties of Competitor because the application doesn't need them. Of course, this is a simple example but we have other cases where tables/fields in the db are not as simple of this and we definitely DON'T want them polluting the object model.

Big Question:
How would the application update these kind of properties? In all cases, the values for these properties are known at a "global" level, like LST_UPD_DATE is the current timestamp. To be more specific, how can I specify the current timestamp value for a property that doesn't exists in any persistent class?

Jeff

Object Model

Competitor:
Long competitorId (PK)
String competitorName

Competitiveness:
String competitivenessDesc

Bid Competitor:
Long bidCompetitorId (PK)
Long bidId
Long competitorId
Competitiveness competitiveness
String notes
boolean wonBid

Data Model/Schema

BP_M_BID_COMPETITOR TABLE:
BID_COMPETITOR_SKEY
BID_ALT_SKEY
COMPETITOR_CD
COMPETITOR_WON_BID_IND
COMPETITOR_NAME
COMPETITOR_COMPETITIVE_CD
COMPETITOR_NOTES_TXT
CREATE_DATE
CREATE_USERID
LST_UPD_DATE
LST_UPD_USERID

BP_R_REF_DATA_LIST TABLE:
TBL_SKEY
TBL_NAME
TBL_DESC
DISC_CD
LST_UPD_DATE
LST_UPD_USERID

BP_R_REF_DATA TABLE:
TBL_SKEY
TBL_KEY_CD
TBL_KEY_DESC
LST_UPD_DATE
LST_UPD_USERID
ACT_STAT_CD
TBL_SORT_SEQ


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2003 9:54 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
There are two possible solutions.

(1) Try to put something together using the new Hibernate 2.1 PropertyAccessor framework. Properties do not really need to be properties anymore!

(2) Chris Nockleberg (on my request) added some new functionality to CGLIB to allow buildtime addition of properties to classes. He also put together an Ant task that will scan your hibernate mappings for things like:

<property name="syntheticProperty" type="int">
<meta name="enhanced">true</meta>
</property>

and add the named property to your class file. The property is then accessible via Hibernate Metadata API, Interceptors, etc.



What do you think of those options?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2003 11:10 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 7:53 pm
Posts: 66
Location: Lakeland, Florida USA
WOW, fantastic. How can I find out more info on ea option? Is the ant task mandatory in #2? Couldn't the properties be added at runtime/start up?

Jeff


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2003 11:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No, nothings mandatory. I understand that it is also possible to add the properties at startup iff you have control over the classloader.



OT: how many people understand what "iff" means? I keep almost writing it and then think "hmmm these people aren't mathematicians....."


;)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2003 12:34 am 
Beginner
Beginner

Joined: Fri Aug 29, 2003 3:39 pm
Posts: 33
Location: San Francisco, CA
The transformation stuff requires CGLIB2, so you'll pretty much have to wait until the next Hibernate release. I'll add some docs to the wiki once it is ready. Gavin, do you know where that ant task ended up? Since it is parsing the mapping file it might be best if it lived in Hibernate CVS eventually.

For transforming classes at load-time (as opposed to build-time) CGLIB uses the Aspectwerkz online mode architecture. The possibilities are quite varied depending on your JVM vendor and version, see here for more details:

http://aspectwerkz.codehaus.org/online.html

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2003 12:34 am 
Beginner
Beginner

Joined: Fri Aug 29, 2003 3:39 pm
Posts: 33
Location: San Francisco, CA
btw, +1 on iff
Chris


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2003 12:05 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 7:53 pm
Posts: 66
Location: Lakeland, Florida USA
Quote:
new Hibernate 2.1 PropertyAccessor framework


Are you refering to:

Hibernate 2.0.2 support for "calculated properties" <property name="foo" formula="bar * baz"/>

and

Hibernate 2.1 beta 4 support for added property access strategies, including access="field" for direct field access, bypassing the get/set pair?

What's valid for formula and access?

Jeff


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2003 12:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Unfortunately both of these dont match what you need

Quote:
Hibernate 2.0.2 support for "calculated properties" <property name="foo" formula="bar * baz"/>


This allows you to have an existing property of your bean automatically calculated from other properties when loading it from the DB

Quote:
Hibernate 2.1 beta 4 support for added property access strategies, including access="field" for direct field access, bypassing the get/set pair?


This allows Hibernate to access fields of your class directly, bypassing getters and setters.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2003 3:33 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 7:53 pm
Posts: 66
Location: Lakeland, Florida USA
Quote:
automatically calculated from other properties when loading it from the DB


Hum... It seems as though this could easily be extened to when saving to the DB. For example,

Code:
<property
        name="createDate"
        type="java.sql.Timestamp"
        column="CREATE_DATE"
        formula="new Date()"
    />


or even

Code:
<property
        name="createUserid"
        type="java.lang.String"
        column="CREATE_USERID"
        formula="ThreadContext.getUserId()"
    />   


Jeff

btw, -1 on iff


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