0

I am reading an Excel file to populate a database table using Hibernate + Apache POI XSSF. For inserting the data, I am using the SETTER methods of the hibernate properties along with session.save() instead of using the traditional INSERT approach.

The problem is that I want to explicitly set NULL values into nullable columns using setter methods when the corresponding Excel cell content is empty.

Please suggest how to achieve this.

1
  • 1
    this should not be community wiki Commented Sep 10, 2010 at 22:07

1 Answer 1

1

Doesn't entity.setFoo(null); work?

Sign up to request clarification or add additional context in comments.

3 Comments

No it is not working. I am keeping the Excel cell as blank for setting null values and I am explicitly calling the setter method passing null as argument. But in the database it is getting inserted as empty string "" instead of null.
run in debug mode and verify this. It is not logical
I got it working finally. The trick was to avoid calling the setter method itself in order to insert null value for that column instead of passing java Null as argument to the setter method. Thanks a lot, Bozho.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.