• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BeanPropertyRowMapper returning mostly nulls in returned objects' fields

 
Mike London
Ranch Hand
Posts: 1208
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 123
Firefox Browser Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the table column names?
 
harshvardhan ojha
Ranch Hand
Posts: 157
1
Android Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is your column name is in camel case ?? like 'firstName' ?
 
Mike London
Ranch Hand
Posts: 1208
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 157
1
Android Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1208
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 123
Firefox Browser Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Mike London
Ranch Hand
Posts: 1208
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic