M
Marc Twain
This might be modelling 101 but I'll give it a go: I'm trying to have
a JavaBean that maps one or more table in a DB.
So I create a 'User' bean. The no arg Constructor is used to create a
brand new user with default properties. Another constructor takes a
Primary key as an argument to create a new user from the database.
Then I add 'save()' and 'update()' methods. So far so good. (I guess)
The problem is, if I add a delete() method, it means I have to
instantiate a user object before calling delete() on itself. Doesn't
make much sense to me!
And finally all goes to hell when I end up having to list a bunch of
users... I don't even know where to place that listUsers() method. As
a static method of the User class?
Does anyone have faced the same problems or am I just approaching the
issue the wrong way? I have 5 java books on J2EE but none of them
cover those modelling issues.
Any idea?
TIA,
AJ
a JavaBean that maps one or more table in a DB.
So I create a 'User' bean. The no arg Constructor is used to create a
brand new user with default properties. Another constructor takes a
Primary key as an argument to create a new user from the database.
Then I add 'save()' and 'update()' methods. So far so good. (I guess)
The problem is, if I add a delete() method, it means I have to
instantiate a user object before calling delete() on itself. Doesn't
make much sense to me!
And finally all goes to hell when I end up having to list a bunch of
users... I don't even know where to place that listUsers() method. As
a static method of the User class?
Does anyone have faced the same problems or am I just approaching the
issue the wrong way? I have 5 java books on J2EE but none of them
cover those modelling issues.
Any idea?
TIA,
AJ