I use a lot of custom finders (i.e. implemented in the bean file itself). I found that if I return null pk value then JBoss returns null (as of 3.0.0). I didn't want this so I throw a FinderException when not found. It sounds like this is exactly what you want. You'll have to implent the SQL yourself, but if it solves your problem. It may not be completely DB independent, but will not require you to put a unique key on the table. BTW, what DB doesn't support UK constraint?
Jon > Date: Thu, 12 Sep 2002 08:11:58 -0700 > From: Brian Macy <[EMAIL PROTECTED]> > To: �[EMAIL PROTECTED] > Subject: [JBoss-user] a finder method that doesn't throw an exception when > not found? Reply-To: [EMAIL PROTECTED] > > I'm having a difficult time as several important pieces of behavior in > my system rely on checks against existence. Right now I just have to > catch the FinderException and handle it there. The problem is that it > appears the FinderException is occurring when there are some transient > database problems too. > > What I need is a finder like function that returns null for not found, > the object if found, and throws exceptions when there are errors. > > What's really hurting is that this is causing data integrity issues > (FinderException thrown, so I end up adding a duplicate item, which then > causes every finder method that assumes it is returning a single object > to also throw an exception). I can deal with some of this by adding > constraints directly to the DB but a significant reason for using J2EE > was to be DB independent. > > Anyways, the death of the system ends up being: > > - sudden high load on the DB > - followed by transactions rollback (DB load stays high) > - removing bean with tx set errors > - OutOfMemory Exceptions and SQL DB running out of connections > - If I'm lucky the system tries to shutdown > > > Actually, maybe I just partially solved my problem. It looks like there > is an ObjectNotFoundException sublcassing FinderException... assuming it > is thrown only when a successful query is made and nothing is found I > should be generally ok. Still, something that returns null would be much > better (without having to return a Collection). > > Brian Macy ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
