-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Flush issue - transaction hangs on commit after flush.
PostPosted: Thu Aug 29, 2013 2:07 am 
Newbie

Joined: Wed Aug 28, 2013 11:03 am
Posts: 2
Hello,

Can you help me understand what I am doing wrong or maybe it is a bug (somewhere).
I have created simple application to reproduce this problem.

My environment details:
Hibernate version: 3.2.6.ga
Database: Oracle
Application server: glassfish 3.1.2.2 (build 5)
Connection pool details:
res-type="javax.sql.ConnectionPoolDataSource"
datasource-classname="oracle.jdbc.pool.OracleConnectionPoolDataSource"
I am using container mange transactions.
Technology: EJB 3.0

Durrng developing the application I have faced with following issue:

Have two tables PARENT and CHILD. CHILD has reference to parent.
In buissnes method I creating new object of Parent type then call em.flush() then create new object of Child type and on this child object I am setting parentId with value from parent object created earlier (everything in the same transaction).

The problem
System prints message "last line" on glassfish console and that is all. Transaction hangs on commit and method never end. (See code example below)
I have also locks on database.

Workaround
Remove em.flush() or add second flush at the end of method.

Different behaviour on other application servers
It is very strange that on JBOSS or Weblogic this problem doesn't occure.

Could you help me understand why it works in this way, please?

Parent entity
Code:
@Entity
@Table(name = "PARENT")
@SequenceGenerator(name = "seqParentRecid", sequenceName = "SEQ_PARENT_ID")
public class Parent implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(generator = "seqParentRecid")
    @Column(name = "ID")
    private long id;
    @Size(max = 20)
    @Column(name = "NAME")
    private String name;
    @OneToMany(mappedBy = "parentId")
    private Collection<Child> childCollection;

    ... geters and setters
}


Child entity
Code:
@Entity
@Table(name = "CHILD")
@SequenceGenerator(name = "seqChildRecid", sequenceName = "SEQ_CHILD_ID")
public class Child implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(generator = "seqChildRecid")
    @Column(name = "ID")
    private long id;
    @Size(max = 20)
    @Column(name = "TEXT")
    private String text;
    @Column(name = "PARENT_ID")
    private long parentId; //foreign key to PARENT(ID)
   
    ... geters and setters
}


Bean implementation
Code:
@Stateless
public class MyBean implements MyBeanLocal {

    @PersistenceContext(name = "GF-TrainingModule-ejbPU")
    EntityManager em;
   
    @Override
    public void createNew() {
        Parent p = new Parent();
        p.setName("New name");
       
        p = (Parent)em.merge(p);
        em.flush();
       
        Child n = new Child();
        n.setText("New text");
        n.setParentId(p.getId());
        em.merge(n);
       
        System.out.println("last line");
    }
}


Persistance xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="GF-TrainingModule-ejbPU" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>TEST</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
      <property name="hibernate.connection.datasource" value="TEST"/>
      <property name="hibernate.connection.provider_class" value="org.hibernate.connection.DatasourceConnectionProvider"/>
      <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
      <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.SunONETransactionManagerLookup"/>
    </properties>
  </persistence-unit>
</persistence>


glassfish-resource.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
    <jdbc-connection-pool
        allow-non-component-callers="false"
        associate-with-thread="false"
        connection-creation-retry-attempts="0"
        connection-creation-retry-interval-in-seconds="10"
        connection-leak-reclaim="false"
        connection-leak-timeout-in-seconds="0"
        connection-validation-method="table"
        datasource-classname="oracle.jdbc.pool.OracleConnectionPoolDataSource"
        fail-all-connections="false"
        idle-timeout-in-seconds="300"
        is-connection-validation-required="false"
        is-isolation-level-guaranteed="true"
        lazy-connection-association="false"
        lazy-connection-enlistment="false"
        match-connections="false"
        max-connection-usage-count="0"
        max-pool-size="32"
        max-wait-time-in-millis="60000"
        name="oracle-thin_TestPool"
        non-transactional-connections="false"
        pool-resize-quantity="2"
        res-type="javax.sql.ConnectionPoolDataSource"
        statement-timeout-in-seconds="-1"
        steady-pool-size="8"
        validate-atmost-once-period-in-seconds="0"
        wrap-jdbc-objects="true">
       
        <property name="User" value="..."/>
        <property name="Password" value="..."/>
        <property name="URL" value="..."/>
        <property name="driverClass" value="oracle.jdbc.OracleDriver"/>
        <property name="serverName" value="..."/>
        <property name="portNumber" value="..."/>
        <property name="databaseName" value="..."/>
    </jdbc-connection-pool>
    <jdbc-resource enabled="true" jndi-name="TEST" object-type="user" pool-name="oracle-thin_TestPool"/>
</resources>


Top
 Profile  
 
 Post subject: Re: Flush issue - transaction hangs on commit after flush.
PostPosted: Wed Sep 25, 2013 7:57 am 
Newbie

Joined: Wed Aug 28, 2013 11:03 am
Posts: 2
bump


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.