I am working on legacy code that uses JPA where the code still calls setFormOfUse() for each database parameter of type NCHAR, NVARCHAR.
- I am aware that there was a time that this was required.
- I am aware that there was a time after that when one could tweak the default setting so that it does not have to be caled for each binding.
Is it still necessary to invoke the setFormOfUse() at this point of time (dec 2016) with the latest JDBC drivers? From which JDBC/Oracle versions one can do what? I can only find snippets of information unrelated from the versions.
Edit 1 - Related Questions
- Getting Hibernate and SQL Server to play nice with VARCHAR and NVARCHAR
- Hibernate with NVARCHAR2
- Using Types.NVARCHAR with oracle JDBC driver to work with Cyrillic chars: This gives a hint that 'setFormOfUse()' is necessary until ojdbc driver 11.2.0.1 (jul. 2009) and you can use setNString from driver 11.2.0.2 (aug 2010).
- Hibernate with NVARCHAR2 This question is interesting because of the Hibernate version information.
Edit 2 - JDBC Spec
I searched the JDBC specs and I found this information:
- JDBC 3.0 (JSR 54; 2002) Nothing in there about NCHAR, NVARCHAR, NCLOB, ...
- JDBC 4.0 (JSR 221; 2006) This mentions setNString() and others. So the earliest year that 'setNString' could replace 'setUseOf' would be 2006. So I will now look at the Hibernate releases and Oracle driver releases from 2006 to find the earliest setNString support (if it is supported).
Edit 3 - Conclusion
Conclusions
- From Oracle ojdbc-11.2.0.2 (aug 2010) and higher you can use the standard JDBC 'setNString()' in stead of the Oracle specific 'setFormOfUse()'.
- If using Hibernate ORM, it is supported from version 4.1.10 and above.
Implications
- If using ojdbc-11.2.0.1 (jul 2009) you should write your own OracleDialect and explicitly call 'setFormOfUse()'.
- If using ojdbc-11.2.0.2 (aug 2010) or higher + Hibernate < 4.1.10 you have to write your own OracleDialect and call 'setNString()'.
- If using ojdbc-11.2.0.2 or higher + Hibernate >= 4.1.10 you don't have to do anything, the conversion will work out-of the box.