aspose file tools *
The moose likes Spring and the fly likes BeanPropertyRowMapper returning mostly nulls in returned objects' fields Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "BeanPropertyRowMapper returning mostly nulls in returned objects Watch "BeanPropertyRowMapper returning mostly nulls in returned objects New topic
Author

BeanPropertyRowMapper returning mostly nulls in returned objects' fields

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1083
Hello,

I have an extremely simple BeanPropertyRowMapper that should be returning several instances of my Customer class, but it's only returning correctly, the CustomerId field within each instance. The other returned fields in each instance are nulls.

Not sure why.

Suggestions?

Thanks,

-mike

================================



======

Customer.java


============

Test Code that runs:



============

Output:

-----------------------------------------
Customer ID: 1
Customer Name = null null
Customer City = null
Customer State = null
Customer Zip = null
-----------------------------------------------------------------
Customer ID: 2
Customer Name = null null
Customer City = null
Customer State = null
Customer Zip = null
-----------------------------------------------------------------
Kathleen Angeles
Ranch Hand

Joined: Aug 06, 2012
Posts: 123

What are the table column names?
harshvardhan ojha
Ranch Hand

Joined: Jul 26, 2007
Posts: 157
    
    1

is your column name is in camel case ?? like 'firstName' ?
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1083
Kathleen Angeles wrote:What are the table column names?


Hi Kathleen,

I should have posted the column names, but since the CUSTOMER_ID field works, I figured the rest of them were OK.

Here are the DB Column Names (all are varchar, except CUSTOMER_ID which is int).

CUSTOMER_ID
CUSTOMER_FIRSTNAME
CUSTOMER_LASTNAME
CUSTOMER_CITY
CUSTOMER_STATE
CUSTOMER_ZIP

My reading up (before posting) on BeanPropertyRowMapper said that it could handle fields in this underscore format, but perhaps not?

--------

Thanks in advance,

-mike
harshvardhan ojha
Ranch Hand

Joined: Jul 26, 2007
Posts: 157
    
    1

true Mike, it mapped customer id by its type, so it should have same name or you can do something like select CUSTOMER_ID as customerId, CUSTOMER_FIRSTNAME as customerFirstName ..... etc
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1083
harshvardhan ojha wrote:true Mike, it mapped customer id by its type, so it should have same name or you can do something like select CUSTOMER_ID as customerId, CUSTOMER_FIRSTNAME as customerFirstName ..... etc


Thanks for your reply.

Unfortunately, that didn't help.

I still get:

Customer ID: 1
Customer Name = null null
Customer City = null
Customer State = null
Customer Zip = null

-- mike
Kathleen Angeles
Ranch Hand

Joined: Aug 06, 2012
Posts: 123

Mike London wrote:
harshvardhan ojha wrote:true Mike, it mapped customer id by its type, so it should have same name or you can do something like select CUSTOMER_ID as customerId, CUSTOMER_FIRSTNAME as customerFirstName ..... etc


Thanks for your reply.

Unfortunately, that didn't help.

I still get:

Customer ID: 1
Customer Name = null null
Customer City = null
Customer State = null
Customer Zip = null

-- mike


What harshvardhan probably meant was that you use the corresponding java field names.

Apply something like below to all the fields that failed.



Above, firstName is used because that is your java field name.

- k


--------------------------------------------------------------------------------------------------------------------------
[SpringSource Certified Spring Professional - Practice Tests]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

He was close.

The field names in the query results have to match the names in the Object.

so

SELECT c.customer_firstName as firstName, c.customer_lastname as lastName FROM Customer c

Alias it with the EXACT same property name for the field.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1083
Mark Spritzler wrote:He was close.

The field names in the query results have to match the names in the Object.

so

SELECT c.customer_firstName as firstName, c.customer_lastname as lastName FROM Customer c

Alias it with the EXACT same property name for the field.

Mark



Yup, that works! Cool.

Thanks Mark and to others who replied as well.



-- mike
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: BeanPropertyRowMapper returning mostly nulls in returned objects' fields