openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruce Beaumont <>
Subject Question re Transaction Persistence Context
Date Mon, 08 Oct 2007 12:53:16 GMT

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 = 
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();
(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">
  <property name="openjpa.ConnectionURL" 
  <property name="openjpa.ConnectionDriverName" 
  <property name="openjpa.ConnectionUserName" value="jdbc"/>
  <property name="openjpa.ConnectionPassword" value="j@v@db0nly"/>
  <property name="openjpa.Log" value="SQL=TRACE"/>

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

Thanks for any guidance


View raw message