How to obtain java.sql.connection to call createBlob?
843830Apr 19 2009 — edited Apr 20 2009Hi,
I am developing a Java Persistence EJB 3.0 application and would like to use BLOB data type with PostgreSQL 8.3. There is a command called "createBlob" in java.sql.connection. However, I have so much problems trying to do it correctly. I have provided a snippet of my code:
Method getUnitOfWorkMethod = entityManager.getClass().getMethod("getUnitOfWork");
Object unitOfWork = getUnitOfWorkMethod.invoke(entityManager, (Object[]) null);
System.out.println("unitOfWork: " + unitOfWork);
Method beginEarlyTransactionMethod = unitOfWork.getClass().getMethod("beginEarlyTransaction");
beginEarlyTransactionMethod.invoke(unitOfWork, (Object[]) null);
Method getAccessorMethod = unitOfWork.getClass().getMethod("getAccessor");
Object accessor = getAccessorMethod.invoke(unitOfWork, (Object[]) null);
System.out.println("accessor: " + accessor);
Class incrementCallCoundMethodParameters[] = new Class[1];
incrementCallCoundMethodParameters[0] = AbstractSession.class;
Method incrementCallCountMethod = accessor.getClass().getMethod("incrementCallCount",
incrementCallCoundMethodParameters);
incrementCallCountMethod.invoke(accessor, new Object[]{unitOfWork});
Method getConnectionMethod = accessor.getClass().getMethod("getConnection");
Object connection = getConnectionMethod.invoke(accessor, (Object[]) null);
System.out.println("connection: " + connection);
Method createBlobMethod = connection.getClass().getMethod("createBlob");
Object blob = createBlobMethod.invoke(connection, (Object[]) null);
System.out.println("blob: " + blob);
The output:
INFO: unitOfWork: UnitOfWork(
DatabaseAccessor(connected)
PostgreSQLPlatform)
INFO: accessor: DatabaseAccessor(connected)
INFO: connection: com.sun.gjc.spi.jdbc40.ConnectionHolder40@5084ebe8
INFO: org.objectsonclouds.exception.ObjectsOnCloudsException: java.lang.reflect.InvocationTargetException
I have tried with both TopLink and EclipseLink and they don't work.
Can any help on how to obtain a "connection" to "createBlob" correctly?
(For reference, there is some information on PostgreSQL web site, but seems that this is not the Java Persistence API way of getting the connection:
http://jdbc.postgresql.org/documentation/83/binary-data.html#binary-data-example)
Thanks in advance!
Kevin.