Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] autocommit problem

You must begin the JPA transaction before calling beginEarlyTransaction(),
you should also not be setting autocommit.

You could also try executing the query as a DataModifyQuery, or first
execute any DataModifyQuery to cause the early transaction.



Jan Vissers wrote:
> 
> Added some diagnostic information in the part that calls the (Oracle)
> Stored procedure:
> 
>         //Diagnostics
>         try {
>             AbstractSession session = (AbstractSession)
> ((JpaEntityManager) getEntityManager()).getActiveSession();
>             Connection dbConnection =
> session.getAccessor().getConnection();
>             logger.debug("Connection information: " +
> System.identityHashCode(dbConnection) + " - autocommit(" +
> dbConnection.getAutoCommit() + ")");
>         } catch (SQLException e) {
>             logger.error("Failed to get diagnostics for connection: " +
> e.getMessage());
>         }
> 
> This diagnostic is printed from within a method call invoked by a
> 'worker' that sets 'stuff' like so:
> 
>             ((UnitOfWork) ((JpaEntityManager)
> entityManager).getActiveSession()).beginEarlyTransaction();
>             AbstractSession session = (AbstractSession)
> ((JpaEntityManager) entityManager).getActiveSession();
>             session.getAccessor().getConnection().setAutoCommit(false);
>             if (!entityManager.getTransaction().isActive()) {
>                 entityManager.getTransaction().begin();
>             }
> 
> What I'm seeing is that the 'dbConnection' - underlying connection is
> the same instance as well as 'autocommit' being 'false'. So my basic
> question is: provided we start by 'beginEarlyTransaction()' and finish
> all by 'commit()' - why would EclipseLink issue a 'commit' by itself?
> 
> This issue has been going on for to long and I want to resolve it. All
> the help is appreciated!
> 
> Thx,
> -J.
> 
> 
> On Tue, 2008-10-28 at 16:52 +0100, Jan Vissers wrote:
>> This doesn't seem to work.
>> 
>> What we're seeing is that beginEarlyTransaction() stops the
>> executeUpdate which is issued from the Stored procedure call from
>> committing the first time, but after that every subsequent call to this
>> Stored Procedure commits the operation.
>> 
>> I'm guessing that autocommit somehow is 'true' and therefor
>> executeUpdate is issuing commit.
>> 
>> Does this make sense?
>> -J.
>> 
>> On Mon, 2008-10-27 at 07:01 -0700, James Sutherland wrote:
>> > By default EclipseLink uses a read connection pool to process read
>> queries
>> > until a flush or data modification query (or locking query) has been
>> > executed.  A DataModifyQuery would can a transaction to start, but a
>> > ValueReadQuery does not.  You can begin a transaction yourself through
>> > getUnitOfWork().beginEarlyTransaction().
>> > 
>> > 
>> > 
>> > Leon Derks-2 wrote:
>> > > 
>> > > When I test the persistImageInfoIntoImageLibrary method, I noticed it 
>> > > also works without beginning a transaction.
>> > >        
>> > >      ImageInfo imageInfo = getImageInfo();
>> > >      imageDAO.persistImageInfoIntoImageLibrary(imageInfo);
>> > > 
>> > > The image is persisted in the table and I didn't started a
>> transaction.
>> > > How is this possible?
>> > > 
>> > > Can someone explain this to me?
>> > > Leon
>> > > 
>> > > 
>> > > Leon Derks wrote:
>> > >> I want to store an image into another db schema, using a stored 
>> > >> function call.
>> > >>
>> > >> I do this by getting the ActiveSession() from my EntityManager, see 
>> > >> the Java code below:
>> > >> In the logging I see the function is executed in eclipselink:
>> > >>
>> > >> The problem is that the image is already stored into the table,
>> before 
>> > >> the transaction has committed.
>> > >> So when I use pl/sql developer and view the table I see that the
>> image 
>> > >> is stored without committing the transaction..
>> > >>
>> > >> The stored function call has no autonomous transaction. So how is
>> this 
>> > >> possible?
>> > >> Does the getActiveSession() has an autocommit?
>> > >>
>> > >>
>> > >> JAVA CODE:
>> > >> public ImageInfo persistImageInfoIntoImageLibrary(ImageInfo
>> imageInfo) {
>> > >>        StoredFunctionCall functionCall = new StoredFunctionCall();
>> > >>        functionCall.setProcedureName("til.cil_api.create_image");
>> > >>        functionCall.addNamedArgument("p_image_id");
>> > >>        functionCall.addNamedArgument("p_image_type_id");
>> > >>        functionCall.addNamedArgument("p_collection_id");
>> > >>        functionCall.addNamedArgument("p_description");
>> > >>
>> > >>        ValueReadQuery query = new ValueReadQuery(functionCall);
>> > >>
>> > >>        query.addArgument("p_image_id");
>> > >>        query.addArgument("p_image_type_id");
>> > >>        query.addArgument("p_collection_id");
>> > >>        query.addArgument("p_description");
>> > >>
>> > >>        List args = new ArrayList();
>> > >>        args.add(null);
>> > >>        args.add(GuideControlConfiguration.getImageTypeId());
>> > >>        args.add(GuideControlConfiguration.getImageCollectionId());
>> > >>        args.add(imageInfo.getVisualElementId());
>> > >>              functionCall.setResult("function_result",
>> Integer.class);
>> > >>
>> > >>        Integer tangeloImageId = (Integer) 
>> > >> getActiveSession().executeQuery(query, args);
>> > >> }
>> > >>
>> > >> private Session getActiveSession() {
>> > >>        return ((JpaEntityManager)
>> getEntityManager()).getActiveSession();
>> > >> }
>> > > 
> 


-----
---
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/autocommit-problem-tp20149191p20227119.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top