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.0Durrng 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 problemSystem 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.
WorkaroundRemove em.flush() or add second flush at the end of method.
Different behaviour on other application serversIt 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 entityCode:
@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 entityCode:
@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 implementationCode:
@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.xmlCode:
<?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>