struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jacob Hookom" <hooko...@uwec.edu>
Subject RE: [OT] OJB or Hibernate??
Date Tue, 01 Apr 2003 02:38:46 GMT
I'm working on an OJB Example app right now that uses User/Role management,
Forum/Posts in 1:N relationships (as a side note, I'm still irked about
tiles and it's heavy use of scriptlets).

GOAL:
"Give me the top 5 most recently posted Forums ordered by most recently
posted to" -- a common thing on forum web sites, and for paging also, show
only 5 (do not cache things in the session, and then page!)


O/R Mapping:
Thread.getPosts() returns a collection in a 1:N mapping
Post.getCreated() returns a Date of when it was created


OJB Query Code:
Collection result = null;
PersistenceBroker broker = PersistenceBrokerFactory.defaultBroker();
try
{
	Query q = new QueryByCriteria(new Thread());
q.getCriteria().addOrderBy("posts.created", sortasc);
	q.setStartAtIndex(0);
	q.setEndAtIndex(5);

	broker.beginTransaction();
	result = broker.getCollectionByQuery(q);
	broker.commitTransaction();
}
finally
{
	broker.close();
}
return result;



OJB GENERATES THIS FOR SQL:

// IF this is the first time querying for this thread via prepared stmt
SELECT A0.thdCreated,A0.thdTitle,A0.thdUsrID,A0.thdThdID,A1.posCreated
FROM tbl_thread A0
	LEFT OUTER JOIN tbl_thread_post A1 ON A0.thdThdID=A1.posThdID
ORDER BY 5 LIMIT 0,5

// Successive calls via prepared statement
SELECT A0.posUsrID,A0.posPosID,A0.posCreated,A0.posContent,A0.posThdID
FROM tbl_thread_post A0
ORDER BY 3 LIMIT 0,5

You can't get much more efficient than that.  Plus, I extended OJB's
SqlCodeGeneratorDefaultImpl (added ONE method) which gave me MySql specific
paging of query results much like Google uses with the LIMIT parameter.

CONCLUSION:
I can't say enough about OJB.  One of the things that irks me is Hibernate's
use of Strings in querying. "This" + "That" + "this"-- if you ever see
benchmarks, can cause extreme slow downs in Java.

| -----Original Message-----
| From: Raible, Matt [mailto:Matt_Raible@cable.comcast.com]
| Sent: Monday, March 31, 2003 3:55 PM
| To: 'Struts Users Mailing List'
| Subject: RE: [OT] OJB or Hibernate??
| 
| Are there any OJB examples with Struts?  The reason I ask is that I know
| of
| two Hibernate/Struts examples:
| 
| http://sf.net/projects/struts
| 
| hibernate and resume modules
| 
| HTH,
| 
| Matt
| 
| > -----Original Message-----
| > From: Tim Shadel [mailto:tim@zserve.com]
| > Sent: Monday, March 31, 2003 2:26 PM
| > To: Struts Users Mailing List
| > Subject: Re: [OT] OJB or Hibernate??
| >
| >
| > For what it's worth, Here's a few links I found through Google:
| >
| > http://www.freeroller.net/page/ceperez/20021212
| > http://www.rollerweblogger.org/page/roller/20021212
| >
| > Tim
| >
| > Bill Johnson wrote:
| > > *This message was transferred with a trial version of
| > CommuniGate(tm) Pro*
| > > I'm curious which is the framework of choice?  What
| > > the strengths are of each, etc.?
| > >
| > > Thanks,
| > >
| > > Bill
| > >
| > > __________________________________________________
| > > Do you Yahoo!?
| > > Yahoo! Platinum - Watch CBS' NCAA March Madness, live on
| > your desktop!
| > > http://platinum.yahoo.com
| > >
| > >
| > ---------------------------------------------------------------------
| > > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
| > > For additional commands, e-mail: struts-user-help@jakarta.apache.org
| > >
| >
| >
| >
| > ---------------------------------------------------------------------
| > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
| > For additional commands, e-mail: struts-user-help@jakarta.apache.org
| >
| 
| 
| ---------------------------------------------------------------------
| To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
| For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message