You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Charles Moulliard <cm...@gmail.com> on 2009/12/08 17:30:49 UTC

camel-bam (Hibernate vs Openjpa)

JPA implementation is radically different between Hibernate and openjpa.

Here is a snapshot of what happens in the transaction who will save the
ProcessDefinition

    protected ProcessDefinition findOrCreateProcessDefinition() {
        Map<String, Object> params = new HashMap<String, Object>(1);
        params.put("name", processName);

        List<ProcessDefinition> list =
CastUtils.cast(jpaTemplate.findByNamedParams("select x from "
            + ProcessDefinition.class.getName() + " x where x.name = :name",
params));
        if (!list.isEmpty()) {
            LOG.info(">> list not empty - Definition : " +
list.get(0).toString() + ", name : " + list.get(0).getName() + ", id : " +
list.get(0).getId());
            return list.get(0);
        } else {
            ProcessDefinition answer = new ProcessDefinition();
            answer.setName(processName);
            LOG.info(">> before persist Definition : " + answer.toString() +
", name : " + answer.getName() + ", id : " + answer.getId());
            jpaTemplate.persist(answer);

            list = CastUtils.cast(jpaTemplate.find("select p from " +
ProcessDefinition.class.getName() +" p "));
            LOG.info(">> Definition name : " + list.get(0).getName() + ", id
: " + list.get(0).getId());
            LOG.info(">> after persist Definition : ");
            return answer;
        }
    }



1) openjpa


2009-12-08 17:24:43,168 [main           ] INFO
ProcessBuilder                 - >> before persist Definition :
org.apache.camel.bam.model.ProcessDefinition[null], name : Process-1, id :
null
2009-12-08 17:24:43,184 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Initiating transaction commit
2009-12-08 17:24:43,184 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Committing JPA transaction on EntityManager
[org.apache.openjpa.persistence.EntityManagerImpl@6ffd79]
2009-12-08 17:24:43,184 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Closing JPA EntityManager
[org.apache.openjpa.persistence.EntityManagerImpl@6ffd79] after transaction
2009-12-08 17:24:43,184 [tyMonitorEngine] DEBUG
EntityManagerFactoryUtils      - Closing JPA EntityManager
2009-12-08 17:24:43,184 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Creating new transaction with name [null]:
PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2009-12-08 17:24:43,184 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Opened new EntityManager
[org.apache.openjpa.persistence.EntityManagerImpl@f38cf0] for JPA
transaction
2009-12-08 17:24:43,184 [tyMonitorEngine] TRACE
SQL                            - <t 15040737, conn 23149395> executing
prepstmnt 31361704 SELECT t0.id, t0.ACTIVITYDEFINITION_ID,
t0.escalationLevel, t0.PROCESSINSTANCE_CORRELATIONKEY,
t0.receivedMessageCount, t0.timeExpected, t0.timeOverdue FROM
CAMEL_ACTIVITYSTATE t0 WHERE (t0.timeOverdue < ?) [params=(Time) 17:24:43]
2009-12-08 17:24:43,184 [tyMonitorEngine] TRACE
SQL                            - <t 15040737, conn 23149395> [0 ms] spent
2009-12-08 17:24:43,184 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Initiating transaction commit
2009-12-08 17:24:43,184 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Committing JPA transaction on EntityManager
[org.apache.openjpa.persistence.EntityManagerImpl@f38cf0]
2009-12-08 17:24:43,184 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Closing JPA EntityManager
[org.apache.openjpa.persistence.EntityManagerImpl@f38cf0] after transaction
2009-12-08 17:24:43,184 [tyMonitorEngine] DEBUG
EntityManagerFactoryUtils      - Closing JPA EntityManager
2009-12-08 17:24:43,184 [tyMonitorEngine] DEBUG
ActivityMonitorEngine          - Sleeping for 1000 millis
2009-12-08 17:24:43,246 [main           ] TRACE
Runtime                        - Updating sequence values.
2009-12-08 17:24:43,246 [main           ] TRACE
Runtime                        - Getting current sequence values.
2009-12-08 17:24:43,246 [main           ] TRACE
SQL                            - <t 14043096, conn 16703414> executing
prepstmnt 4123674 SELECT SEQUENCE_VALUE FROM OPENJPA_SEQUENCE_TABLE WHERE ID
= ? [params=(int) 0]
2009-12-08 17:24:43,246 [main           ] TRACE
SQL                            - <t 14043096, conn 16703414> [0 ms] spent
2009-12-08 17:24:43,246 [main           ] TRACE
Runtime                        - Inserting row for this mapping into
sequence table.
2009-12-08 17:24:43,246 [main           ] TRACE
SQL                            - <t 14043096, conn 32633742> executing
prepstmnt 17912146 INSERT INTO OPENJPA_SEQUENCE_TABLE (ID, SEQUENCE_VALUE)
VALUES (?, ?) [params=(int) 0, (int) 1]
2009-12-08 17:24:43,246 [main           ] TRACE
SQL                            - <t 14043096, conn 32633742> [0 ms] spent
2009-12-08 17:24:43,246 [main           ] TRACE
Runtime                        - Updating sequence values.
2009-12-08 17:24:43,246 [main           ] TRACE
Runtime                        - Getting current sequence values.
2009-12-08 17:24:43,246 [main           ] TRACE
SQL                            - <t 14043096, conn 16183734> executing
prepstmnt 28117049 SELECT SEQUENCE_VALUE FROM OPENJPA_SEQUENCE_TABLE WHERE
ID = ? [params=(int) 0]
2009-12-08 17:24:43,246 [main           ] TRACE
SQL                            - <t 14043096, conn 16183734> [0 ms] spent
2009-12-08 17:24:43,246 [main           ] TRACE
SQL                            - <t 14043096, conn 16183734> executing
prepstmnt 7806641 UPDATE OPENJPA_SEQUENCE_TABLE SET SEQUENCE_VALUE = ? WHERE
ID = ? AND SEQUENCE_VALUE = ? [params=(long) 51, (int) 0, (long) 1]
2009-12-08 17:24:43,262 [main           ] TRACE
SQL                            - <t 14043096, conn 16183734> [16 ms] spent
2009-12-08 17:24:43,278 [main           ] TRACE
SQL                            - <t 14043096, conn 31352855> executing
prepstmnt 1732792 INSERT INTO CAMEL_PROCESSDEFINITION (id, name) VALUES (?,
?) [params=(long) 1, (null) null]
2009-12-08 17:24:43,278 [main           ] TRACE
SQL                            - <t 14043096, conn 31352855> [0 ms] spent
2009-12-08 17:24:43,278 [main           ] TRACE
SQL                            - <t 14043096, conn 31352855> executing
prepstmnt 13969258 SELECT t0.id, t0.name FROM CAMEL_PROCESSDEFINITION t0
2009-12-08 17:24:43,278 [main           ] TRACE
SQL                            - <t 14043096, conn 31352855> [0 ms] spent
2009-12-08 17:24:43,278 [main           ] DEBUG
TransactionTemplate            - Initiating transaction rollback on
application exception
java.lang.NullPointerException
    at
org.apache.openjpa.kernel.StateManagerImpl.beforeRead(StateManagerImpl.java:939)
    at
org.apache.openjpa.kernel.StateManagerImpl.accessingField(StateManagerImpl.java:1479)
    at
org.apache.camel.bam.model.ProcessDefinition.getName(ProcessDefinition.java)
    at
org.apache.camel.bam.ProcessBuilder.findOrCreateProcessDefinition(ProcessBuilder.java:216)
    at
org.apache.camel.bam.ProcessBuilder.getProcessDefinition(ProcessBuilder.java:145)
    at
org.apache.camel.bam.ProcessBuilder$1.doInTransactionWithoutResult(ProcessBuilder.java:103)
    at
org.springframework.transaction.support.TransactionCallbackWithoutResult.doInTransaction(TransactionCallbackWithoutResult.java:33)
    at
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128)

2) Hibernate

2009-12-08 17:19:18,496 [main           ] INFO
ProcessBuilder                 - >> before persist Definition :
org.apache.camel.bam.model.ProcessDefinition[null], name : Process-1, id :
null
2009-12-08 17:19:18,496 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Creating new transaction with name [null]:
PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2009-12-08 17:19:18,496 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Opened new EntityManager
[org.hibernate.ejb.EntityManagerImpl@120cb3] for JPA transaction
2009-12-08 17:19:18,512 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Initiating transaction commit
2009-12-08 17:19:18,512 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Committing JPA transaction on EntityManager
[org.hibernate.ejb.EntityManagerImpl@120cb3]
2009-12-08 17:19:18,512 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Closing JPA EntityManager
[org.hibernate.ejb.EntityManagerImpl@120cb3] after transaction
2009-12-08 17:19:18,512 [tyMonitorEngine] DEBUG
EntityManagerFactoryUtils      - Closing JPA EntityManager
2009-12-08 17:19:18,512 [tyMonitorEngine] DEBUG
ActivityMonitorEngine          - Sleeping for 984 millis
2009-12-08 17:19:18,684 [main           ] INFO
ProcessBuilder                 - >> after persist Definition :

2009-12-08 17:22:22,293 [main           ] INFO
ProcessBuilder                 - >> before persist Definition :
org.apache.camel.bam.model.ProcessDefinition[null], name : Process-1, id :
null
2009-12-08 17:22:22,293 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Initiating transaction commit
2009-12-08 17:22:22,293 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Committing JPA transaction on EntityManager
[org.hibernate.ejb.EntityManagerImpl@6fdca5]
2009-12-08 17:22:22,293 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Closing JPA EntityManager
[org.hibernate.ejb.EntityManagerImpl@6fdca5] after transaction
2009-12-08 17:22:22,293 [tyMonitorEngine] DEBUG
EntityManagerFactoryUtils      - Closing JPA EntityManager
2009-12-08 17:22:22,309 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Creating new transaction with name [null]:
PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2009-12-08 17:22:22,325 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Opened new EntityManager
[org.hibernate.ejb.EntityManagerImpl@10699ea] for JPA transaction
2009-12-08 17:22:22,325 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Initiating transaction commit
2009-12-08 17:22:22,325 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Committing JPA transaction on EntityManager
[org.hibernate.ejb.EntityManagerImpl@10699ea]
2009-12-08 17:22:22,325 [tyMonitorEngine] DEBUG
JpaTransactionManager          - Closing JPA EntityManager
[org.hibernate.ejb.EntityManagerImpl@10699ea] after transaction
2009-12-08 17:22:22,325 [tyMonitorEngine] DEBUG
EntityManagerFactoryUtils      - Closing JPA EntityManager
2009-12-08 17:22:22,325 [tyMonitorEngine] DEBUG
ActivityMonitorEngine          - Sleeping for 984 millis
2009-12-08 17:22:22,528 [main           ] INFO
ProcessBuilder                 - >> Definition name : Process-1, id : 1
2009-12-08 17:22:22,528 [main           ] INFO
ProcessBuilder                 - >> after persist Definition :

Regards,

Charles Moulliard
Senior Enterprise Architect
Apache Camel Committer

*****************************
blog : http://cmoulliard.blogspot.com
twitter : http://twitter.com/cmoulliard
Linkedlin : http://www.linkedin.com/in/charlesmoulliard

Apache Camel Group :
http://www.linkedin.com/groups?home=&gid=2447439&trk=anet_ug_hm