camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Charles Moulliard <cmoulli...@gmail.com>
Subject Re: camel-example-etl & openJPA (If this is a new instance, make sure any version and/or auto-generated primary key fields are null/default when persisting)
Date Mon, 07 Dec 2009 13:00:59 GMT
I have understand why we have this error :

In fact, within the CustomerTransformer class, the method findCustomerByName
(which is called) uses 'template.persist(answer);' who will inform Spring to
insert in the DB a customerEntity object if it not find from the SQL query.
Next, the same object is send to the JPA endpoint who will detect that the
object has not been detached.

That means that attachment/detachment of objects does not occur in the same
way using Hibernate, JPA, ... as the code works for Hibernate

Does anybody knows what was the intend to use this code in the transform
class ?

**
* Finds a customer for the given username, or creates and inserts a new one
*/
protected CustomerEntity findCustomerByName(JpaTemplate template, String
user) {
List<CustomerEntity> list = CastUtils.cast(template.find("select x from " +
CustomerEntity.class.getName() + " x where x.userName = ?1", user));
if (list.isEmpty()) {
CustomerEntity answer = new CustomerEntity();
answer.setUserName(user);
template.persist(answer);
return answer;
} else {
return list.get(0);
}
}

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


On Mon, Dec 7, 2009 at 1:11 PM, Charles Moulliard <cmoulliard@gmail.com>wrote:

> When I try to use the example camel-example-etl with openJPA, here is the
> error that I receive
>
> [ Camel thread 0: FileComponent] Tracer                         INFO
> be7ae591-e2ea-4021-8179-d6bdd5f5398c >>> (route1)  -->
> jpa://org.apache.camel.ex
> ample.etl.CustomerEntity?consumeLockEntity=true <<< Pattern:InOnly,
> Headers:{CamelFileNameOnly=row2.xml,
> CamelFileAbsolutePath=D:\Dvlpt\Java\workspace
> \apache-camel-source\examples\camel-example-etl\src\data\row2.xml,
> CamelFileRelativePath=row2.xml, CamelFileName=row2.xml,
> CamelFilePath=src\data\row2
> .xml, CamelFileParent=src\data, CamelFileAbsolute=false,
> CamelFileLength=982, CamelFileLastModified=Tue Jul 14 10:37:40 CEST 2009},
> BodyType:org.apach
> e.camel.example.etl.PersonDocument, Body:<person
> user="hiram"><firstName>Hiram</firstName><lastName>Chirino</lastName><city>Tampa</city></person>
> 16094  camel  TRACE  [Camel thread 0: FileComponent] openjpa.jdbc.SQL - <t
> 12662763, conn 1634627> executing prepstmnt 585058
> SELECT t0.id, t0.city, t0.firstName, t0.phone, t0.street, t0.surname,
>         t0.userName, t0.zip
>     FROM Customer t0
>     WHERE (t0.userName = ?)
> [params=(String) hiram]
> 16094  camel  TRACE  [Camel thread 0: FileComponent] openjpa.jdbc.SQL - <t
> 12662763, conn 1634627> [0 ms] spent
> [ Camel thread 0: FileComponent] CustomerTransformer            DEBUG
> Created customer: Customer[userName: hiram firstName: Hiram surname:
> Chirino]
> 16110  camel  TRACE  [Camel thread 0: FileComponent] openjpa.jdbc.SQL - <t
> 12662763, conn 21035203> executing prepstmnt 19041450
> SELECT t0.city, t0.firstName, t0.phone, t0.street, t0.surname,
>         t0.userName, t0.zip
>     FROM Customer t0
>     WHERE t0.id = ?
> [params=(long) 0]
> 16110  camel  TRACE  [Camel thread 0: FileComponent] openjpa.jdbc.SQL - <t
> 12662763, conn 21035203> [0 ms] spent
> [ Camel thread 0: FileComponent] DefaultErrorHandler            DEBUG
> Failed delivery for exchangeId: be7ae591-e2ea-4021-8179-d6bdd5f5398c. On
> deliver
> y attempt: 0 caught:
> org.springframework.dao.DataIntegrityViolationException: Attempt to persist
> detached object "org.apache.camel.example.etl.Custome
> rEntity@8bfa09".  If this is a new instance, make sure any version and/or
> auto-generated primary key fields are null/default when persisting.; nested
> exception is <openjpa-1.3.0-SNAPSHOT-r422266:881892 nonfatal store error>
> org.apache.openjpa.persistence.EntityExistsException: Attempt to persist det
> ached object "org.apache.camel.example.etl.CustomerEntity@8bfa09".  If
> this is a new instance, make sure any version and/or auto-generated primary
> key
>  fields are null/default when persisting.
>
> Anybody has an idea to avoid this ?
>
> 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
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message