Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Beginning Java and the fly likes getters & setters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "getters & setters" Watch "getters & setters" New topic

getters & setters

yoga raj

Joined: Jul 08, 2004
Posts: 1
I am a newbie and trying to learn, I have a type & service table

t_id (fk)

For a Add Screen, I have Type in a text field & JTable for the service (can be multiple for one type).

Now normally when it is recommended to have getters & setters for everything, how do i have setters for the JTable (ie corresponding to the service table).

I don't want to basically go back and forth the database 50 times , ie do the setter, insert to db, and repeat.

Both are in the same screen as per the UI design ? How does everyone normally does this ?

Thanks much
Greg Charles

Joined: Oct 01, 2001
Posts: 2967

Welcome to Java! Normally people use data transfer objects (DTO) in this case, although this gets a bit beyond a beginner question. Basically, a DTO allows you to load a bunch of related data from the database all at once. After it's loaded, the DTO can be accessed directly by the JTable code or whatever else through its getters (and possibly setters) without hitting the database again. Of course, you have to worry about things like stale data, how to handle updates, etc. In many situations, simple DTO objects are sufficient. In others, you might need to use entity EJBs hosted on a J2EE application server.
I agree. Here's the link:
subject: getters & setters
It's not a secret anymore!