Matt RaibleMatt Raible is a Java Champion and Developer Advocate at Okta. developer.okta.com

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

ChainedExceptions and BeanUtils.copyProperties

I am wondering about a few things, so thought I'd try and get some help from the best source I know - the java.blogs community. First, an update on last night. I experienced some difficulty with Hibernate (persisting child objects) and Struts (nightly build doesn't quite work right with Tiles and Modules) and gave up at 2:00 a.m. Luckily, my head cleared up this morning after a deep 4 hours of sleep and I figured out Hibernate and it appears that a fix for the Tiles/Modules problem was checked into CVS by Cedric.

Now I'm wondering if it's possible to use declared exceptions in Struts to grab all your Exceptions from the bottom up. I can do this in an Action (or even a filter) using the following:

// caught exception e
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR,
           new ActionError("errors.general"));

while (e != null) {
    errors.add(ActionErrors.GLOBAL_ERROR,
               new ActionError("errors.detail", e.getMessage()));
    e = (Exception) e.getCause();
}

request.setAttribute(Globals.ERROR_KEY, errors);

Can I do this with declared exceptions? Man that would be sweet if I could - I wouldn't have to have any exception handling in my Actions. Maybe that's the easy way out, but it also makes for rapid development - and you can always add them in when you really want them. Two other things I need to do.

  • I have a java.util.Set on my User (Hibernate) object. This refers to a collection of Resume objects. When I generate my StrutsForms, I need to do something in my XDoclet template to turn a java.util.Set into a java.util.ArrayList. I don't know that I have to do this, but I've always used ArrayLists or Vectors on ActionForms for child objects.
  • I am using BeanUtils.copyProperties in a Business Delegate to transfer properties from my User object to a UserForm object. When I do this, the child objects come through as Resume objects - where I really want them to come through as ResumeForms. Is this possible using BeanUtils, or do I have to do this manually?

I should probably do some research now to try and figure this stuff out on my own - but hopefully an answer will come through while I'm doing that ;-). I'll post to the proper mailing lists if I can't figure it out by COB. BTW, if you're using Hibernate, the FAQ is awesome. I wish more OSS (or closed-source software) had documentation this good.

Posted in Java at Dec 27 2002, 11:40:40 AM MST 9 Comments
Comments:

I don't see why your ChainedExceptions idea wouldn't work - cool. On the other issues: From my (limited) experience, there isn't much key difference btwn Set & ArrayList (except Set restricts you to one copy of an object in its list). Otherwise they work the same (may have different performance profiles). I haven't used BeanUtils.copyProperties (I can think of a couple places I should have, had I know about it), so I cannot answer that question. But does ResumeForm inherit from Resume? Looks like you could implement Converter to coerce Resume to ResumeForm...

Posted by Lance on December 27, 2002 at 01:36 PM MST #

One possibility is to use a Hibernate <bag> instead of a Set (bags implement List on the Java side). However, you need to be careful about making these kinds of decisions where performance is critical. In Hibernate, bags and sets have quite different performance characteristics (though its now hard to say that one is always better than the other).

Posted by Gavin on December 27, 2002 at 05:34 PM MST #

The first line should read "a Hibernate <bag>" ;)

Posted by Gavin on December 27, 2002 at 05:35 PM MST #

Where can I find more information on set vs. bag? Probably the FAQ, eh ;)

Posted by Matt on December 27, 2002 at 06:49 PM MST #

Yeah, theres a couple of items in the FAQ, but we could probably do with a whole page of the Wiki describing the pos and cons of <list> vs <set> vs <bag>. I don't have time to write it now, unfortunately.

Posted by Gavin on December 27, 2002 at 10:43 PM MST #

Thats list vs set vs bag; did it again!

Posted by Gavin on December 27, 2002 at 10:44 PM MST #

Hello all: This is a first time post. I am using BeanUtils.copyProperties to convert my formatted String Form date fields to java.sql.Date for my DTO. I am new to this approach and am experiencing a datatype mismatch problem. I need a simple way to use the BeanUtils.copyProperties to make this happen and have had no luck. Since I am working on a *real* project I am getting nervous. Would someone please point me in the right direction? Thanks in advance! gary_grubb@agilent.com

Posted by Gary Grubb on June 02, 2003 at 10:16 AM MDT #

I created a post a while back about set vs. bag in Hibernate. Here's the link: http://www.stevenradack.com/2005/12/hibernate-set-vs-bag.html

Posted by Steven Radack on January 02, 2006 at 08:15 PM MST #

Hi I am new to struts.could anyone please tell me what would Beanutils.copyProperties do.. and also how to use saveToken and resetToken... any examples would be more helpful my mail id is rickcharles_b@yahoo.com Thanks & Regards Rick

Posted by Rick Charles on July 22, 2006 at 01:04 AM MDT #

Post a Comment:
  • HTML Syntax: Allowed