Bug #2111 add a rs.copy(busObject) method
Submitted: 14 Dec 2003 5:44 Modified: 15 Dec 2003 7:06
Reporter: Ralf Hauser Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S4 (Feature request)
Version:0312 nightly OS:Any (any)
Assigned to: Mark Matthews CPU Architecture:Any

[14 Dec 2003 5:44] Ralf Hauser
Description:
Recently, I learned to appreciate the existence of 
org.apache.commons.beanutils.PropertyUtils or rather its
PropertyUtils.copyProperties (http://jakarta.apache.org/commons/beanutils/api/org/apache/commons/beanutils/PropertyUtils...))

Similarly, it would be great to have the equivalent to have the content from a ResultSet copied into a  business Object.
Additional parameter my be hints on the naming scheme used between Java and MySQL:
For example, a Java "private boolean isActive" may be a mysql "tinyint isactive" but also "is_active"

I guess this is a little bit less efficient in execution time, but it may save the programmer so many (, possibly error-prone) single copy statements that at least for a prototype implementation, it is very worthwhile to have such a method.

What do you think?

How to repeat:
.

Suggested fix:
.
[14 Dec 2003 6:24] Mark Matthews
There are many fine frameworks that already do this, like Hibernate, OJB, Torque, , JDO, etc. There is also talk in the JDBC expert group for JDBC-4.0 to have some rudimentary object-relational-mapping support. Until there is a standard for JDBC, I recommend you investigate one of the existing O-R frameworks out there, because it is unlikely we will add a non-standard method of doing this to the JDBC driver.
[15 Dec 2003 0:46] Ralf Hauser
thx for the hint.
But don't these all add much more overhead than just the copy-related one?
Wouldn't one loose the control over the exact sql statement when using those?
[15 Dec 2003 7:06] Mark Matthews
Object-relational mapping is a complex topic, and even a 'simple' mapper like you propose has a lot of caveats once you start talking about making the data 'flow' in both directions (in and out of the database), as well as managing state correctly. 

If you take a look at many of the tools I mentioned, many of them can in some cases be _faster_ than straight JDBC, because of the caching they can do, as well as writing more efficient queries than most developers can (Hibernate is one example of this).
[16 Dec 2003 23:32] Ralf Hauser
Mark, just stumbled over 
http://jakarta.apache.org/commons/dbutils/apidocs/org/apache/commons/dbutils/handlers/Bean...
and http://jakarta.apache.org/commons/dbutils/apidocs/org/apache/commons/dbutils/handlers/Bean...
Do you have any experience with those?
Could they do what I want?
Rgds r.