openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruce Beaumont <bruce.beaum...@ucs-solutions.co.za>
Subject Question re Transaction Persistence Context
Date Mon, 08 Oct 2007 12:53:16 GMT
Hi

I am using OpenJPA outside a container.

I have found that if I do a select, update a field of the returned object and 
then do a transaction the state of the object is persisted to the database. 
My reading of chapter 7.3.1 (3rd chapter) indicates that this is behavior is 
incorrect as each read outside a transaction should return a detached object 
and that any updates to a detached object should not be persisted.

Here is a small test application

EntityManagerFactory emf = 
Persistence.createEntityManagerFactory("BRUCE-DEV");
EntityManager em = emf.createEntityManager();

(1) SimpleBean sb = em.find(SimpleBean.class, 2);

log.debug("Bean 1 - " + sb);
(2) sb.setDescription("Run 6");

(4)// em.clear();
EntityTransaction et = em.getTransaction();
et.begin();
(3) et.commit();


According to my reading of the manual the bean (1) is outside a transaction 
and thus is detached (Which is what I would like) however the table is 
updates with the value set in (2) when the commit of the transaction happens 
in (3).

If you put in the clear (4) you do get the correct operation but to my 
understanding this should not be required.



My config file is as followes
<persistence-unit name="BRUCE-DEV" transaction-type="RESOURCE_LOCAL">
            
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
        
<class>dao.SimpleBean</class>
          
<properties>
  <property name="openjpa.ConnectionURL" 
value="jdbc:informix-sqli://10.221.9.8:52001/bruce:informixserver=moatslxd;INFORMIXCONRETRY=3;INFORMIXCONTIME=20"/>
  <property name="openjpa.ConnectionDriverName" 
value="com.informix.jdbc.IfxDriver"/>
  <property name="openjpa.ConnectionUserName" value="jdbc"/>
  <property name="openjpa.ConnectionPassword" value="j@v@db0nly"/>
  <property name="openjpa.Log" value="SQL=TRACE"/>
</properties>
</persistence-unit>


By bean is defined as followes
@Entity(name="simple")
@Table(name="simple")
public class SimpleBean {
 
  @Id
  @Column(name="s_id", nullable=false)
  private long id = 0;
  
  @Basic
  @Column(name="s_key", length=10, nullable=true)
  private String key = null;
  
  @Basic
  @Column(name="s_desc", length=30, nullable=true)
  private String description = null;
  
  @Basic
  @Column(name="s_decimal", scale=14, precision=2, nullable=true)
  public BigDecimal dec = null;
  
  @Basic
  @Column(name="s_date", nullable=true)
  public Calendar date = null;
  
  @Basic
  @Column(name="s_dt", nullable=true)
  public Calendar dt = null;
}



Thanks for any guidance

Bruce

Mime
View raw message