How to use PreparedStatements with the Persistence Manager?
I have a few pieces of code that use native PreparedStatements, but am having trouble using them in conjunction with the PersistenceManager. The current approach is:
Connection conn = (Connection)persistenceManager.getDataStoreConnection.getNativeConnection();
org.datanucleus.exceptions.NucleusUserException: The Connection was acquired by the developer and must be closed before using the persistence API.
I have managed to track the issue down to fact that the NativeConnection is being closed instead of the DataStoreConnection being closed.
Does JDO spec identify/specify the requirements/contract for using PreparedStatements? Or is this part of the DN implementation only? Are there any examples that I can review to help identify best practices for using PreparedStatements within DataNucleus (I couldn't find anything in the datanucleus/samples-jdo repo)? I did find a snippet of code on the DN Persistence pages but I'm not sure if I need to close the native connection as well or not.
If, instead of using the PM.getDataSource().getNativeConnection(), I were to use the PMF to get a brand new PM and new NativeConnection, if I only close the native connection (ie: nativeConnection.close()), will that cause a memory leak? Am I always required to close the JDOConnection as well?