Naming Boolean variable in Spring MVC with respect to Database

We have a boolean column and we defined it as isActive.

The ajax request is success. However unable to bind the variable and exception is thrown

getter name is isActive() and setter name is setIsActive()

1. We don't want to rename the column as isActive to active
2. What should be the good setter and getter when the column is isActive ?
3. What should be the good setter and getter when the column is active ?

Software ProgrammerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
What are you mapping with? Hibernate? something else?

As for typical ways of naming getters/setters, if you had a field called "active", you would have "isActive()" and "setActive(...)". If you had to have a field called "isActive", you would have "isIsActive()" and "setIsActive(...)". (Which sounds a bit funny, which is why you should have the first version, and then if you can't change the column name, you set up your mapping to map "isActive" column to "active" field)
Software ProgrammerAuthor Commented:
We don't use Hibernate. Instead using native SQL queries via Spring JDBCTemplate. I agree isIsActive()  doesn't seems to be good. But the question is

1. why isActive is not recognizable for isActive column ???
2. does the variable name matters in binding the object or the method name??

Some says specification says that...But i don't have clarity. can u please share your insights on the above two.
mccarlIT Business Systems Analyst / Software DeveloperCommented:
We don't use Hibernate. Instead using native SQL queries via Spring JDBCTemplate

So, are you using code similar to what I gave you in another question of yours? Where I showed how to use the NamedParameterJdbcTemplate?

If so, then I explained in that question that it doesn't matter one bit what your column names are compared to your bean names. You can have a column named "Fred" and a Java POJO with a field named "Bob" and you can write the SQL query to map between the two.

In this case, you can keep you column name "isActive" and just write the SQL properly so that it maps to the "active" field in your POJO. I believe if you are using the BeanPropertySqlParameterSource that I showed you, then the getters/setters HAVE to be correctly named, ie. if you refer to a SQL parameter as    ":active"   in the SQL, then the field should be called active, the getter called isActive, and the setter called setActive.

As to your questions, they are not very clear, if the above hasn't cleared up your understanding, can you please try and restate the questions (preferrably with some code to demonstrate) ?
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Software ProgrammerAuthor Commented:
I agree with what you are saying. We can close this if you could give some details on the java specification if any on the Boolean when we don't use the bean property mapper. instead binding Java Objects with just RowMapper.
mccarlIT Business Systems Analyst / Software DeveloperCommented:
"just RowMapper" doesn't do ANY binding and so no, there isn't any specification. It is all up to your manual code, eg.

jdbcTemplate.query("select name, isActive from someTable", new RowMapper<SomePojo>() {
    public SomePojo mapRow(ResultSet rs, int rowNum) throws SQLException {
        SomePojo pojo = new SomePojo();
        return pojo;

Open in new window

You can see even here, that there doesn't have to be a corelation between column name and pojo field names. In this case, the "isActive" column is the 2nd column selected in the SQL, and so you call ".setActive()" passing the value of the 2nd column. The column name or the setter method of the POJO could be entirely different.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Software ProgrammerAuthor Commented:
We got exception the type cannot be binded. When the column name is isActive in the database and we have the method name as isActive
mccarlIT Business Systems Analyst / Software DeveloperCommented:
You need to copy/paste the exact Exception that you are getting and post it here, include the full thing, stack trace and all. And the exact code that you are using.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.