Hi Enrique, As far as I remember, that is not the default behaviour. I've checked the spec, section 3.2.2 Persisting an Entity Instance and my understanding is that the persist operation is only applied by explicitly calling persist on the object, or via a cascade. I'm not familiar with how Spring Boot sets up the PU, but there is a configuration, cascade-persist, that you can apply to all mappings, Maybe Spring Boot does it under the covers. Do you have an orm.xml configuration file? Cheers,Roberto From: Enrique Rodríguez Lasterra <laste...@gmail.com> To: users@openjpa.apache.org; Roberto Cortez <radcor...@yahoo.com> Sent: Thursday, August 4, 2016 2:20 AM Subject: Re: Migration from hibernate Maybe is a configuration of springboot...i load hibernate with spring..but when i execute my example, when i do entitmanager.persist(customer), hibernate first execute a select of customertype table and them the insert of customer table. I was thinking that JPA first try to find on the database if the PrimaryKey of the child object exists....but it seems openjpa don't do it. Regards. 2016-08-03 22:24 GMT+02:00 Roberto Cortez <radcor...@yahoo.com.invalid>:
Hi Enrique, Strange. I was almost certain that Hibernate would work that way as well. If just leave the defaults one, the EntityManager doesn't know what to do with a detached entity instance. I've tried with one sample project and this is what I get with Hibernate:org.hibernate. TransientPropertyValueExceptio n: object references an unsaved transient instance If I add the Cascade then it works fine. Maybe you have Cascade set up somewhere else? Cheers,Roberto From: Enrique Rodríguez Lasterra <laste...@gmail.com> To: users@openjpa.apache.org Sent: Wednesday, August 3, 2016 5:29 AM Subject: Migration from hibernate Hi, i'm new on the list. I'm migrating a project from tomcat+hibernate to websphere+openjpa2.2.3 My problem is with a @ManyToOne relationship. I have a Customer entity with a relationship with CustomerType. When i create a new customer i don't whant to save-update customertype. This pseudo-code work with hibernate Customer c = new Customer(); CustomerType ct = new CustomerType(); ct.setPk(1); c.setCustomerType(ct); .... entityManager.persist(c); When i execute it with openjpa, i get an exception that CustomerType is detached and i shoud user Cascade.Persist, but this is not what i want. I know that one way to resolve the problema is to find CustomerType on EntityManager instead to create a new object for that... but this change is very complex in my application. Is this a problem of openjpa or hibernate implementation? -- ______________________________ _ Enrique Rodriguez Lasterra lasterra AT gmail DOT com -- _______________________________ Enrique Rodriguez Lasterra lasterra AT gmail DOT com