This week's giveaway is in the Spring forum.
We're giving away four copies of Microservices Testing (Live Project) and have Chris Love & Andres Sacco on-line!
See this thread for details.
Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

BeanPropertyRowMapper returning mostly nulls in returned objects' fields

 
Bartender
Posts: 1884
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
-----------------------------------------------------------------
 
Ranch Hand
Posts: 123
Firefox Browser Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are the table column names?
 
Ranch Hand
Posts: 157
1
Android MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is your column name is in camel case ?? like 'firstName' ?
 
Mike London
Bartender
Posts: 1884
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1884
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1884
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic