views:

49

answers:

1

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  A: 

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

Bozho
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.
SAGGI
run in debug mode and verify this. It is not logical
Bozho
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.
SAGGI