Hi All,
I have kind of run into this situation wherein I need to set null value to an object's property. I have some existing records in a table and I need to set null value to a column for all of them. I understand the Java null is totally different from a SQL Null. For e.g.
String aString = null; SomeObject aObject = new SomeObject(); aObject.setSomeProperty(aString ); session.save(aObject);
will not result in the column mapped to the SomeProperty property being set with a SQL Null. What goes through to the table will be the text "null". So querying the following will not retrieve the record,
select * from someTable where someProperty is null
How do I go about setting the SQL null value to the column of a record? One solution I thought about was deleting the record and creating a new object updating all properties except the one I wanted to set SQL null for....but it was impractical in my case as there a lot of records and in my case its difficult to remember all the "other" properties in some collection(difficult? i cudnt think of how to do it :-) )
Please let me know how I can achieve this one....even if its through HQL...Here are some questions you would like answered before u try solving this one..
1. Yes the column of interest is nullable ( but of course!)
2. Yes Its ok if it can be done through HQL
3. I am using Oracle
4. My code runs in a non-managed environment
5. I am not using caching
thanx a tonne in advance...help me out on this one!
|