On Mon, Dec 7, 2009 at 2:00 PM, Charles Moulliard <[email protected]> wrote:
> 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 ?
>

No I guess many of those "standards" are still problematic to use as
some impl. do X and others do Y.
I guess maybe some detach or whatever needs to be added when it
inserts the customer.

Can you not try looking into this as you are messing with it already?


> **
> * 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 <[email protected]>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
>> rent...@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.customerent...@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
>>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Reply via email to