[jira] Created: (DBUTILS-57) BeanProcessor not able to map an alias column from a HSQLDB query to the any bean properties

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] Created: (DBUTILS-57) BeanProcessor not able to map an alias column from a HSQLDB query to the any bean properties

JIRA jira@apache.org
BeanProcessor not able to map an alias column from a HSQLDB query to the any bean properties
--------------------------------------------------------------------------------------------

                 Key: DBUTILS-57
                 URL: https://issues.apache.org/jira/browse/DBUTILS-57
             Project: Commons DbUtils
          Issue Type: Bug
         Environment: hsqldb-1.9.0-rc4 memory mode
DBUtils 1.2
            Reporter: Wynand


Using a query with an alias, hsqldb engine doesn't populate the column name metadata only the column label metadata.

In such a case the column isn't mapped.

To resolve this, the column label should be used in case the column name is not available.

Here is a snippet from org.apache.commons.dbutils.BeanProcessor.mapColumnsToProperties line 393 :

...
       for (int col = 1; col <= cols; col++) {            
            String columnName = rsmd.getColumnName(col);

           // columnName is empty, revert to column label
            if (columnName.length() == 0) {
                columnName = rsmd.getColumnLabel(col);
            }            
            ...

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (DBUTILS-57) BeanProcessor not able to map an alias column from a HSQLDB query to the any bean properties

JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/DBUTILS-57?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12768614#action_12768614 ]

Julien Aymé commented on DBUTILS-57:
------------------------------------

IMHO, the column label should be used in the first place, and reverted to the column name if the label is null or empty.
This would allow to automatically map query like this:

{code}
SELECT
    i.id,
    i.price,
    t1.label AS name,
    t2.label AS description,
    t3.label AS tooltip
FROM items i
    JOIN texts t1 ON i.lname_id = t1.id
    JOIN texts t2 ON i.ldescr_id = t2.id
    JOIN texts t3 ON i.ltool_id = t3.id
WHERE i.id = ?
    AND t1.lang_id = ?
    AND t2.lang_id = ?
    AND t3.lang_id =?
{code}

What do you think?

> BeanProcessor not able to map an alias column from a HSQLDB query to the any bean properties
> --------------------------------------------------------------------------------------------
>
>                 Key: DBUTILS-57
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-57
>             Project: Commons DbUtils
>          Issue Type: Bug
>         Environment: hsqldb-1.9.0-rc4 memory mode
> DBUtils 1.2
>            Reporter: Wynand
>
> Using a query with an alias, hsqldb engine doesn't populate the column name metadata only the column label metadata.
> In such a case the column isn't mapped.
> To resolve this, the column label should be used in case the column name is not available.
> Here is a snippet from org.apache.commons.dbutils.BeanProcessor.mapColumnsToProperties line 393 :
> ...
>        for (int col = 1; col <= cols; col++) {            
>             String columnName = rsmd.getColumnName(col);
>            // columnName is empty, revert to column label
>             if (columnName.length() == 0) {
>                 columnName = rsmd.getColumnLabel(col);
>             }            
>             ...

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (DBUTILS-57) BeanProcessor not able to map an alias column from a HSQLDB query to the any bean properties

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/DBUTILS-57?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12768616#action_12768616 ]

Julien Aymé commented on DBUTILS-57:
------------------------------------

From the javadoc description of the getColumnLabel method (see http://java.sun.com/javase/6/docs/api/java/sql/ResultSetMetaData.html#getColumnLabel%28int%29 )

"Gets the designated column's suggested title for use in printouts and displays. The suggested title is usually specified by the SQL AS clause. If a SQL AS is not specified, the value returned from getColumnLabel will be the same as the value returned by the getColumnName method."

> BeanProcessor not able to map an alias column from a HSQLDB query to the any bean properties
> --------------------------------------------------------------------------------------------
>
>                 Key: DBUTILS-57
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-57
>             Project: Commons DbUtils
>          Issue Type: Bug
>         Environment: hsqldb-1.9.0-rc4 memory mode
> DBUtils 1.2
>            Reporter: Wynand
>
> Using a query with an alias, hsqldb engine doesn't populate the column name metadata only the column label metadata.
> In such a case the column isn't mapped.
> To resolve this, the column label should be used in case the column name is not available.
> Here is a snippet from org.apache.commons.dbutils.BeanProcessor.mapColumnsToProperties line 393 :
> ...
>        for (int col = 1; col <= cols; col++) {            
>             String columnName = rsmd.getColumnName(col);
>            // columnName is empty, revert to column label
>             if (columnName.length() == 0) {
>                 columnName = rsmd.getColumnLabel(col);
>             }            
>             ...

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (DBUTILS-57) BeanProcessor not able to map an alias column from a HSQLDB query to the any bean properties

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/DBUTILS-57?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12768709#action_12768709 ]

wynand commented on DBUTILS-57:
-------------------------------

Right.

It seems then the actual problem lies with HSQLDB's getLabel() method.


> BeanProcessor not able to map an alias column from a HSQLDB query to the any bean properties
> --------------------------------------------------------------------------------------------
>
>                 Key: DBUTILS-57
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-57
>             Project: Commons DbUtils
>          Issue Type: Bug
>         Environment: hsqldb-1.9.0-rc4 memory mode
> DBUtils 1.2
>            Reporter: Wynand
>
> Using a query with an alias, hsqldb engine doesn't populate the column name metadata only the column label metadata.
> In such a case the column isn't mapped.
> To resolve this, the column label should be used in case the column name is not available.
> Here is a snippet from org.apache.commons.dbutils.BeanProcessor.mapColumnsToProperties line 393 :
> ...
>        for (int col = 1; col <= cols; col++) {            
>             String columnName = rsmd.getColumnName(col);
>            // columnName is empty, revert to column label
>             if (columnName.length() == 0) {
>                 columnName = rsmd.getColumnLabel(col);
>             }            
>             ...

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (DBUTILS-57) BeanProcessor not able to map an alias column from a HSQLDB query to the any bean properties

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/DBUTILS-57?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12769986#action_12769986 ]

Julien Aymé commented on DBUTILS-57:
------------------------------------

This request is coherent to what has been done into the last BeanUtils release: see issue BEANUTILS-344.

> BeanProcessor not able to map an alias column from a HSQLDB query to the any bean properties
> --------------------------------------------------------------------------------------------
>
>                 Key: DBUTILS-57
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-57
>             Project: Commons DbUtils
>          Issue Type: Bug
>         Environment: hsqldb-1.9.0-rc4 memory mode
> DBUtils 1.2
>            Reporter: Wynand
>
> Using a query with an alias, hsqldb engine doesn't populate the column name metadata only the column label metadata.
> In such a case the column isn't mapped.
> To resolve this, the column label should be used in case the column name is not available.
> Here is a snippet from org.apache.commons.dbutils.BeanProcessor.mapColumnsToProperties line 393 :
> ...
>        for (int col = 1; col <= cols; col++) {            
>             String columnName = rsmd.getColumnName(col);
>            // columnName is empty, revert to column label
>             if (columnName.length() == 0) {
>                 columnName = rsmd.getColumnLabel(col);
>             }            
>             ...

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (DBUTILS-57) BeanProcessor not able to map an alias column from a HSQLDB query to the any bean properties

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/DBUTILS-57?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Julien Aymé updated DBUTILS-57:
-------------------------------

    Attachment: BeanProcessorTest.patch
                BeanProcessor.patch

Attaching patch for BeanProcessor and unit test.

> BeanProcessor not able to map an alias column from a HSQLDB query to the any bean properties
> --------------------------------------------------------------------------------------------
>
>                 Key: DBUTILS-57
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-57
>             Project: Commons DbUtils
>          Issue Type: Bug
>         Environment: hsqldb-1.9.0-rc4 memory mode
> DBUtils 1.2
>            Reporter: Wynand
>         Attachments: BeanProcessor.patch, BeanProcessorTest.patch
>
>
> Using a query with an alias, hsqldb engine doesn't populate the column name metadata only the column label metadata.
> In such a case the column isn't mapped.
> To resolve this, the column label should be used in case the column name is not available.
> Here is a snippet from org.apache.commons.dbutils.BeanProcessor.mapColumnsToProperties line 393 :
> ...
>        for (int col = 1; col <= cols; col++) {            
>             String columnName = rsmd.getColumnName(col);
>            // columnName is empty, revert to column label
>             if (columnName.length() == 0) {
>                 columnName = rsmd.getColumnLabel(col);
>             }            
>             ...

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Closed: (DBUTILS-57) BeanProcessor not able to map an alias column from a HSQLDB query to the any bean properties

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/DBUTILS-57?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dan Fabulich closed DBUTILS-57.
-------------------------------

       Resolution: Fixed
    Fix Version/s: 1.3

Committed revision 832535.  Thanks for the patch!

> BeanProcessor not able to map an alias column from a HSQLDB query to the any bean properties
> --------------------------------------------------------------------------------------------
>
>                 Key: DBUTILS-57
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-57
>             Project: Commons DbUtils
>          Issue Type: Bug
>         Environment: hsqldb-1.9.0-rc4 memory mode
> DBUtils 1.2
>            Reporter: Wynand
>             Fix For: 1.3
>
>         Attachments: BeanProcessor.patch, BeanProcessorTest.patch
>
>
> Using a query with an alias, hsqldb engine doesn't populate the column name metadata only the column label metadata.
> In such a case the column isn't mapped.
> To resolve this, the column label should be used in case the column name is not available.
> Here is a snippet from org.apache.commons.dbutils.BeanProcessor.mapColumnsToProperties line 393 :
> ...
>        for (int col = 1; col <= cols; col++) {            
>             String columnName = rsmd.getColumnName(col);
>            // columnName is empty, revert to column label
>             if (columnName.length() == 0) {
>                 columnName = rsmd.getColumnLabel(col);
>             }            
>             ...

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (DBUTILS-57) BeanProcessor not able to map an alias column from a HSQLDB query to the any bean properties

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/DBUTILS-57?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12773188#action_12773188 ]

Dan Fabulich commented on DBUTILS-57:
-------------------------------------

Note that unlike Wynand's suggestion, Julien's patch prefers to use column label, falling back to column name if column label is not available.

> BeanProcessor not able to map an alias column from a HSQLDB query to the any bean properties
> --------------------------------------------------------------------------------------------
>
>                 Key: DBUTILS-57
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-57
>             Project: Commons DbUtils
>          Issue Type: Bug
>         Environment: hsqldb-1.9.0-rc4 memory mode
> DBUtils 1.2
>            Reporter: Wynand
>             Fix For: 1.3
>
>         Attachments: BeanProcessor.patch, BeanProcessorTest.patch
>
>
> Using a query with an alias, hsqldb engine doesn't populate the column name metadata only the column label metadata.
> In such a case the column isn't mapped.
> To resolve this, the column label should be used in case the column name is not available.
> Here is a snippet from org.apache.commons.dbutils.BeanProcessor.mapColumnsToProperties line 393 :
> ...
>        for (int col = 1; col <= cols; col++) {            
>             String columnName = rsmd.getColumnName(col);
>            // columnName is empty, revert to column label
>             if (columnName.length() == 0) {
>                 columnName = rsmd.getColumnLabel(col);
>             }            
>             ...

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.