Reducing code of ResultSet DTOs

A

Alex

Hi Everyone,

I'm new to Java. I'm writing an app in Struts and am transferring data from
the database to the view layer. My DTOs that I create are more of a mundane
exercise. (getters and setters) Is there a dynamic way of creating
DTOs/JavaBeans?

Thanks!
 
A

Alex

Hi Everyone,

I'm new to Java. I'm writing an app in Struts and am transferring data
from the database to the view layer. My DTOs that I create are more of
a mundane exercise. (getters and setters) Is there a dynamic way of
creating DTOs/JavaBeans?

Thanks!

Actually, to clear up my post, I've read that the most common way to return
values from a database is to iterate through a ResultSet and creating an
object that holds a copy of the data of each row. Then placing the objects
in a collection. What happens when you're returning a table of 20 or 30
columns. That's quite a bit of typing. Is there a simplier way to do this?
 
J

James McGill

Is there a dynamic way of creating
DTOs/JavaBeans?

I use Castor. While it's not a JAXB implementation, it has a builder
that will create your DTOs by parsing an XML schema.

For DAO, I then just write hibernate mappings for these objects. We
have a custom doclet for doing this but I don't use it. It's too easy
just to do it, the automation becomes an extra layer of complexity that
we don't need.
 
J

john gresh

You could write a code generator that reads the data dictionary of the
database (eg all_tables, all_tab_columns, etc. in oracle) and generates
the appropriate .java file for a specified table or collection of
tables.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top