Re: JPA issue: A parent cannot be established or changed once an object has been persisted.

2013-06-05 Thread Nermin
Dear Juan,

thank you for a fast reply.
Yes I would like to use unidirectional mapping, but in combination with 
@PrePersist method at a child entity which changes one parameter value. 

Here is my code:

@Entity
public class CompanyUD {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@org.datanucleus.api.jpa.annotations.Extension(vendorName = 
"datanucleus", key = "gae.encoded-pk", value = "true")
private String id;

 @OneToOne(cascade=CascadeType.ALL)
 @JoinColumn(name="admin_user")
 TradesmanUD adminUser;

private String name;

.. get / Set
}

@Entity
public class TradesmanUD {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@org.datanucleus.api.jpa.annotations.Extension(vendorName = 
"datanucleus", key = "gae.encoded-pk", value = "true")
private String id;

private String name;

//@PrePersist
//public void myPrePers(){
//setName("Some different Name");
//}


.. get / set
}

// == My call:

private void testOneToOne() {
CompanyUD company = new CompanyUD();
company.setName("MyTest Company");

TradesmanUD user = new TradesmanUD();
user.setName("My test Admin");

company.setAdminUser(user);

EntityManager em = emfInstance.createEntityManager();
em.persist(company);
em.close();
}

The code above works fine without the @PrePersist method at TradesmanUD (UD 
stays for unidirectional)

With @PrePersist in place i get the following ERROR:

*Detected attempt to establish CompanyUD(no-id-yet) as the parent of 
TradesmanUD(52) but the entity identified by TradesmanUD(52) has already been 
persisted without a parent.  A parent cannot be established or changed once an 
object has been persisted.*



I am using JPA with DataNucleus on Google Appengine. 

Thank you for your help!

Nermin



Am Mittwoch, 5. Juni 2013 16:03:59 UTC+2 schrieb Juan Pablo Gardella:
>
> I've assumed you are trying to use unidirectional mapping. Check 
> http://uaihebert.com/?p=1674&page=19
>
>
>
> 2013/6/5 Nermin >
>
>> Dear Juan, Dear GWT Group
>>
>> thank you very much for your help. I fixed most of my problems by 
>> following your advice. All @OneToMany relations work fine after I made sure 
>> the @ManyToOne relation is populated manually as you suggested.
>>
>> Unfortunately I cannot get @OneToOne relation running wen @PrePerist is 
>> used on a child.
>>
>> My sample code is here:
>> https://dl.dropboxusercontent.com/u/2983671/JPA_Problem/JPA_Problem.zip
>>
>> Two Classes: CompanyX, TradesmanX
>> CompanyX stays in a OneToOne owned relation with TradesmanX
>> I use @PrePersist on TradesmanX in order to pre-set some fields before 
>> the Object gets persisted in the DB.
>>
>> @Entity
>> public class CompanyX {
>> ...
>> @OneToOne(cascade=CascadeType.ALL)
>> private TradesmanX adminUser;
>> }
>>
>>
>> @Entity
>> public class TradesmanX {
>> ...
>> @PrePersist
>> public void myMethod(){
>> System.out.println("Pre Persist");
>> this.setFirstName("USER_X");
>> }
>> ...
>> }
>>
>> //Here is how I persist them within my test servlet:
>>
>> private void testPersistenceTwo() {
>>
>> CompanyX company = new CompanyX();
>> company.setName("my Comp");
>>
>> TradesmanX user = new TradesmanX();
>> user.setFirstName("Test_FName");
>> user.setLastName("Test_Lname");
>>
>> company.setAdminUser(user);
>> company.persist();
>> }
>>
>>
>> I am getting a similar error to the previous one:
>> javax.persistence.PersistenceException: Detected attempt to establish 
>> CompanyX(no-id-yet) as the parent of TradesmanX(7) but the entity 
>> identified by TradesmanX(7) has already been persisted without a parent.  A 
>> parent cannot be established or changed once an object has been persisted.
>>
>> Is there a solution for this?
>> Would it be possible to provide some working example?
>>
>> Thank you in advance:
>>
>> Nermin
>>
>>
>>
>>
>>
>> Am Donnerstag, 23. Mai 2013 15:09:41 UTC+2 schrieb Nermin:
>>>
>>> When I try to do that, I get a following error:
>>>
>>> java.lang.NullPointerException
>>> at 
>>> com.google.appengine.**datanucleus.StoreFieldManager.**storeRelations(**StoreFieldManager.java:848)
>>> at 
>>> com.google.appengine.**datanucleus.**DatastorePersistenceHandler.**insertObjectsInternal(**DatastorePersistenceHandler.**java:367)
>>> at 
>>> com.google.appengine.**datanucleus.**DatastorePersistenceHandler.**insertObject(**DatastorePersistenceHandler.**java:218)
>>> at 
>>> org.datanucleus.state.**JDOStateManager.**internalMakePersistent(**JDOStateManager.java:2377)
>>> at 
>>> org.datanucleus.state.**JDOStateManager.flush(**JDOStateManager.java:3769)
>>> at 
>>> org.datanucleus.state.**JDOStateManager.**getExternalObjectId(**JDOStateManager.java:1088)
>>> at 
>>> org.datanucleus.state.**JDOStateManager.getO

Re: JPA issue: A parent cannot be established or changed once an object has been persisted.

2013-06-05 Thread Juan Pablo Gardella
I've assumed you are trying to use unidirectional mapping. Check
http://uaihebert.com/?p=1674&page=19



2013/6/5 Nermin 

> Dear Juan, Dear GWT Group
>
> thank you very much for your help. I fixed most of my problems by
> following your advice. All @OneToMany relations work fine after I made sure
> the @ManyToOne relation is populated manually as you suggested.
>
> Unfortunately I cannot get @OneToOne relation running wen @PrePerist is
> used on a child.
>
> My sample code is here:
> https://dl.dropboxusercontent.com/u/2983671/JPA_Problem/JPA_Problem.zip
>
> Two Classes: CompanyX, TradesmanX
> CompanyX stays in a OneToOne owned relation with TradesmanX
> I use @PrePersist on TradesmanX in order to pre-set some fields before the
> Object gets persisted in the DB.
>
> @Entity
> public class CompanyX {
> ...
> @OneToOne(cascade=CascadeType.ALL)
> private TradesmanX adminUser;
> }
>
>
> @Entity
> public class TradesmanX {
> ...
> @PrePersist
> public void myMethod(){
> System.out.println("Pre Persist");
> this.setFirstName("USER_X");
> }
> ...
> }
>
> //Here is how I persist them within my test servlet:
>
> private void testPersistenceTwo() {
>
> CompanyX company = new CompanyX();
> company.setName("my Comp");
>
> TradesmanX user = new TradesmanX();
> user.setFirstName("Test_FName");
> user.setLastName("Test_Lname");
>
> company.setAdminUser(user);
> company.persist();
> }
>
>
> I am getting a similar error to the previous one:
> javax.persistence.PersistenceException: Detected attempt to establish
> CompanyX(no-id-yet) as the parent of TradesmanX(7) but the entity
> identified by TradesmanX(7) has already been persisted without a parent.  A
> parent cannot be established or changed once an object has been persisted.
>
> Is there a solution for this?
> Would it be possible to provide some working example?
>
> Thank you in advance:
>
> Nermin
>
>
>
>
>
> Am Donnerstag, 23. Mai 2013 15:09:41 UTC+2 schrieb Nermin:
>>
>> When I try to do that, I get a following error:
>>
>> java.lang.NullPointerException
>>  at 
>> com.google.appengine.**datanucleus.StoreFieldManager.**storeRelations(**StoreFieldManager.java:848)
>>  at 
>> com.google.appengine.**datanucleus.**DatastorePersistenceHandler.**insertObjectsInternal(**DatastorePersistenceHandler.**java:367)
>>  at 
>> com.google.appengine.**datanucleus.**DatastorePersistenceHandler.**insertObject(**DatastorePersistenceHandler.**java:218)
>>  at 
>> org.datanucleus.state.**JDOStateManager.**internalMakePersistent(**JDOStateManager.java:2377)
>>  at 
>> org.datanucleus.state.**JDOStateManager.flush(**JDOStateManager.java:3769)
>>  at 
>> org.datanucleus.state.**JDOStateManager.**getExternalObjectId(**JDOStateManager.java:1088)
>>  at 
>> org.datanucleus.state.**JDOStateManager.getObjectId(**JDOStateManager.java:958)
>>  at 
>> com.emajstor.server.**persistence.Company.**jdoGetObjectId(Company.java)
>>  at 
>> org.datanucleus.api.jpa.**JPAAdapter.getIdForObject(**JPAAdapter.java:272)
>>  at 
>> com.google.appengine.**datanucleus.EntityUtils.**getKeyForObject(EntityUtils.**java:245)
>>  at 
>> com.google.appengine.**datanucleus.EntityUtils.**getParentKey(EntityUtils.java:**853)
>>  at 
>> com.google.appengine.**datanucleus.StoreFieldManager.**establishEntityGroup(**StoreFieldManager.java:939)
>>  at 
>> com.google.appengine.**datanucleus.**DatastorePersistenceHandler.**insertObjectsInternal(**DatastorePersistenceHandler.**java:244)
>>  at 
>> com.google.appengine.**datanucleus.**DatastorePersistenceHandler.**insertObject(**DatastorePersistenceHandler.**java:218)
>>  at 
>> org.datanucleus.state.**JDOStateManager.**internalMakePersistent(**JDOStateManager.java:2377)
>>  at 
>> org.datanucleus.state.**JDOStateManager.flush(**JDOStateManager.java:3769)
>>  at 
>> org.datanucleus.**ObjectManagerImpl.**flushInternalWithOrdering(**ObjectManagerImpl.java:3884)
>>  at 
>> org.datanucleus.**ObjectManagerImpl.**flushInternal(**ObjectManagerImpl.java:3807)
>>  at 
>> org.datanucleus.**ObjectManagerImpl.flush(**ObjectManagerImpl.java:3747)
>>  at 
>> org.datanucleus.**ObjectManagerImpl.preCommit(**ObjectManagerImpl.java:4137)
>>  at 
>> org.datanucleus.**ObjectManagerImpl.**transactionPreCommit(**ObjectManagerImpl.java:428)
>>  at 
>> org.datanucleus.**TransactionImpl.**internalPreCommit(**TransactionImpl.java:400)
>>  at org.datanucleus.**TransactionImpl.commit(**TransactionImpl.java:288)
>>  at 
>> org.datanucleus.**ObjectManagerImpl.close(**ObjectManagerImpl.java:1090)
>>  at 
>> org.datanucleus.api.jpa.**JPAEntityManager.close(**JPAEntityManager.java:193)
>>  at com.emajstor.server.**persistence.Company.persist(**Company.java:110)
>>  at 
>> com.emajstor.server.test.**MyTestServlet.**testPersistenceOne(**MyTestServlet.java:74)
>>  at 
>> com.emajstor.server.test.**MyT

Re: JPA issue: A parent cannot be established or changed once an object has been persisted.

2013-06-05 Thread Nermin
Dear Juan, Dear GWT Group

thank you very much for your help. I fixed most of my problems by following 
your advice. All @OneToMany relations work fine after I made sure the 
@ManyToOne relation is populated manually as you suggested.

Unfortunately I cannot get @OneToOne relation running wen @PrePerist is 
used on a child.

My sample code is here:
https://dl.dropboxusercontent.com/u/2983671/JPA_Problem/JPA_Problem.zip

Two Classes: CompanyX, TradesmanX
CompanyX stays in a OneToOne owned relation with TradesmanX
I use @PrePersist on TradesmanX in order to pre-set some fields before the 
Object gets persisted in the DB.

@Entity
public class CompanyX {
...
@OneToOne(cascade=CascadeType.ALL)
private TradesmanX adminUser;
}


@Entity
public class TradesmanX {
...
@PrePersist
public void myMethod(){
System.out.println("Pre Persist");
this.setFirstName("USER_X");
}
...
}

//Here is how I persist them within my test servlet:

private void testPersistenceTwo() {

CompanyX company = new CompanyX();
company.setName("my Comp");

TradesmanX user = new TradesmanX();
user.setFirstName("Test_FName");
user.setLastName("Test_Lname");
   
company.setAdminUser(user);
company.persist();
}


I am getting a similar error to the previous one:
javax.persistence.PersistenceException: Detected attempt to establish 
CompanyX(no-id-yet) as the parent of TradesmanX(7) but the entity 
identified by TradesmanX(7) has already been persisted without a parent.  A 
parent cannot be established or changed once an object has been persisted.

Is there a solution for this?
Would it be possible to provide some working example?

Thank you in advance:

Nermin





Am Donnerstag, 23. Mai 2013 15:09:41 UTC+2 schrieb Nermin:
>
> When I try to do that, I get a following error:
>
> java.lang.NullPointerException
>   at 
> com.google.appengine.datanucleus.StoreFieldManager.storeRelations(StoreFieldManager.java:848)
>   at 
> com.google.appengine.datanucleus.DatastorePersistenceHandler.insertObjectsInternal(DatastorePersistenceHandler.java:367)
>   at 
> com.google.appengine.datanucleus.DatastorePersistenceHandler.insertObject(DatastorePersistenceHandler.java:218)
>   at 
> org.datanucleus.state.JDOStateManager.internalMakePersistent(JDOStateManager.java:2377)
>   at 
> org.datanucleus.state.JDOStateManager.flush(JDOStateManager.java:3769)
>   at 
> org.datanucleus.state.JDOStateManager.getExternalObjectId(JDOStateManager.java:1088)
>   at 
> org.datanucleus.state.JDOStateManager.getObjectId(JDOStateManager.java:958)
>   at com.emajstor.server.persistence.Company.jdoGetObjectId(Company.java)
>   at 
> org.datanucleus.api.jpa.JPAAdapter.getIdForObject(JPAAdapter.java:272)
>   at 
> com.google.appengine.datanucleus.EntityUtils.getKeyForObject(EntityUtils.java:245)
>   at 
> com.google.appengine.datanucleus.EntityUtils.getParentKey(EntityUtils.java:853)
>   at 
> com.google.appengine.datanucleus.StoreFieldManager.establishEntityGroup(StoreFieldManager.java:939)
>   at 
> com.google.appengine.datanucleus.DatastorePersistenceHandler.insertObjectsInternal(DatastorePersistenceHandler.java:244)
>   at 
> com.google.appengine.datanucleus.DatastorePersistenceHandler.insertObject(DatastorePersistenceHandler.java:218)
>   at 
> org.datanucleus.state.JDOStateManager.internalMakePersistent(JDOStateManager.java:2377)
>   at 
> org.datanucleus.state.JDOStateManager.flush(JDOStateManager.java:3769)
>   at 
> org.datanucleus.ObjectManagerImpl.flushInternalWithOrdering(ObjectManagerImpl.java:3884)
>   at 
> org.datanucleus.ObjectManagerImpl.flushInternal(ObjectManagerImpl.java:3807)
>   at org.datanucleus.ObjectManagerImpl.flush(ObjectManagerImpl.java:3747)
>   at 
> org.datanucleus.ObjectManagerImpl.preCommit(ObjectManagerImpl.java:4137)
>   at 
> org.datanucleus.ObjectManagerImpl.transactionPreCommit(ObjectManagerImpl.java:428)
>   at 
> org.datanucleus.TransactionImpl.internalPreCommit(TransactionImpl.java:400)
>   at org.datanucleus.TransactionImpl.commit(TransactionImpl.java:288)
>   at org.datanucleus.ObjectManagerImpl.close(ObjectManagerImpl.java:1090)
>   at 
> org.datanucleus.api.jpa.JPAEntityManager.close(JPAEntityManager.java:193)
>   at com.emajstor.server.persistence.Company.persist(Company.java:110)
>   at 
> com.emajstor.server.test.MyTestServlet.testPersistenceOne(MyTestServlet.java:74)
>   at com.emajstor.server.test.MyTestServlet.doGet(MyTestServlet.java:39)
>   at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
>   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>   at 
> org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
>   at 
> org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
>   at 
> com.google.appengine.api.socket.dev.De

Re: JPA issue: A parent cannot be established or changed once an object has been persisted.

2013-05-23 Thread Nermin
When I try to do that, I get a following error:

java.lang.NullPointerException
at 
com.google.appengine.datanucleus.StoreFieldManager.storeRelations(StoreFieldManager.java:848)
at 
com.google.appengine.datanucleus.DatastorePersistenceHandler.insertObjectsInternal(DatastorePersistenceHandler.java:367)
at 
com.google.appengine.datanucleus.DatastorePersistenceHandler.insertObject(DatastorePersistenceHandler.java:218)
at 
org.datanucleus.state.JDOStateManager.internalMakePersistent(JDOStateManager.java:2377)
at 
org.datanucleus.state.JDOStateManager.flush(JDOStateManager.java:3769)
at 
org.datanucleus.state.JDOStateManager.getExternalObjectId(JDOStateManager.java:1088)
at 
org.datanucleus.state.JDOStateManager.getObjectId(JDOStateManager.java:958)
at com.emajstor.server.persistence.Company.jdoGetObjectId(Company.java)
at 
org.datanucleus.api.jpa.JPAAdapter.getIdForObject(JPAAdapter.java:272)
at 
com.google.appengine.datanucleus.EntityUtils.getKeyForObject(EntityUtils.java:245)
at 
com.google.appengine.datanucleus.EntityUtils.getParentKey(EntityUtils.java:853)
at 
com.google.appengine.datanucleus.StoreFieldManager.establishEntityGroup(StoreFieldManager.java:939)
at 
com.google.appengine.datanucleus.DatastorePersistenceHandler.insertObjectsInternal(DatastorePersistenceHandler.java:244)
at 
com.google.appengine.datanucleus.DatastorePersistenceHandler.insertObject(DatastorePersistenceHandler.java:218)
at 
org.datanucleus.state.JDOStateManager.internalMakePersistent(JDOStateManager.java:2377)
at 
org.datanucleus.state.JDOStateManager.flush(JDOStateManager.java:3769)
at 
org.datanucleus.ObjectManagerImpl.flushInternalWithOrdering(ObjectManagerImpl.java:3884)
at 
org.datanucleus.ObjectManagerImpl.flushInternal(ObjectManagerImpl.java:3807)
at org.datanucleus.ObjectManagerImpl.flush(ObjectManagerImpl.java:3747)
at 
org.datanucleus.ObjectManagerImpl.preCommit(ObjectManagerImpl.java:4137)
at 
org.datanucleus.ObjectManagerImpl.transactionPreCommit(ObjectManagerImpl.java:428)
at 
org.datanucleus.TransactionImpl.internalPreCommit(TransactionImpl.java:400)
at org.datanucleus.TransactionImpl.commit(TransactionImpl.java:288)
at org.datanucleus.ObjectManagerImpl.close(ObjectManagerImpl.java:1090)
at 
org.datanucleus.api.jpa.JPAEntityManager.close(JPAEntityManager.java:193)
at com.emajstor.server.persistence.Company.persist(Company.java:110)
at 
com.emajstor.server.test.MyTestServlet.testPersistenceOne(MyTestServlet.java:74)
at com.emajstor.server.test.MyTestServlet.doGet(MyTestServlet.java:39)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at 
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at 
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at 
com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
at 
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at 
com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123)
at 
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at 
com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
at 
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at 
com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:61)
at 
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at 
com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at 
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at 
com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
at 
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at 
com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
at 
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at 
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at 
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at 
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at 
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at 
com.google.appengine.tools.de

Re: JPA issue: A parent cannot be established or changed once an object has been persisted.

2013-05-23 Thread Juan Pablo Gardella
In the loop, do user.setCompany(company). You need a transaction. Create it
and do the commit.


2013/5/23 Nermin 

> Dear Juan,
>
> For this purpose I use the GWT-s Request Factory.
> However, in order to simplify the problem, I have created a server side
> persistence example using a simple servlet where one company and two users
> are created. Please have a look at the MyTestServlet.java within the Zip
> File.
>
> https://dl.dropboxusercontent.**com/u/2983671/JPA_Problem/JPA_**
> Problem.zip
>
> The funny thing is, I get now a different Eror:
>
> javax.persistence.PersistenceException: Illegal argument
> 
> Caused by: java.lang.IllegalArgumentException: cross-group transaction
> need to be explicitly specified, see TransactionOptions.Builder.withXGfound
> both Element {
>   type: "Tradesman"
>   id: 361
> }
>  and Element {
>   type: "Tradesman"
>   id: 362
> }
>
> When I remove the @PrePersit from "User class" it works just fine!
> The Error pops up as soon as i modify a parameter on "Tradesman" entity
> (more exactly on its parent class "User").
>
> I really do not understand this behavior. ... I also must admit that I am
> not very advanced in JPA.
>
> Thank you for very much for your help.
>
> Best regards:
>
> Nermin
>
>
> Am Mittwoch, 22. Mai 2013 15:28:50 UTC+2 schrieb Juan Pablo Gardella:
>>
>> Show how you are persisting the entities.
>>
>>
>> 2013/5/22 Nermin 
>>
>>> Dear Alfredo and Juan,
>>>
>>> obviously there is an hidden problem with my code i simply do not see.
>>> Could you please have a short look at these 3 classes (full code) and
>>> tell me what am I doing wrong here:
>>>
>>> https://dl.dropboxusercontent.**com/u/2983671/JPA_Problem/JPA_**
>>> Problem.zip
>>>
>>> Please note: Everything works fine as log as I do not try to make any
>>> changes to the Tradesman entity (its parameters).
>>> When is set new password or any other parameter, i get an error message
>>> of type:
>>>
>>> Detected attempt to establish Company(no-id-yet) as the parent of
>>> Tradesman(358) but the entity identified by Tradesman(358) has already been
>>> persisted without a parent.  A parent cannot be established or changed once
>>> an object has been persisted.
>>>
>>> I am using: JPA with DataNucleus on Google Datastore. (Standard setting
>>> that come with GWT 2.5)
>>>
>>> Thank you in advance for your help!!
>>>
>>> Best regards:
>>>
>>> Nermin
>>>
>>>
>>> Am Dienstag, 21. Mai 2013 18:29:54 UTC+2 schrieb Alfredo
>>> Quiroga-Villamil:

 Or use a cascade persist, merge to force creation or merge respectively

 Sent from my iPhone

 On May 21, 2013, at 7:02 AM, Juan Pablo Gardella 
 wrote:

 You should persist company before persist Tradesman or attach to an
 existent company. This relation should be explicit. Create
 company.addTrademan(Trademan t) method:

 company.addTrademan(Trademan t){
 users.add(t);
 t.setCompany(this);
 }

 Call this in a transactional method.

 Juan






 2013/5/21 Nermin 

> Dear Juan,
>
> I tried *@ManyToOne(optional=false)*, unfortunately no changes.
> In my current setting, the @PrePersist is called only once. (I see it
> on system out) That means: no multiple attempts to persist Tradesman 
> entity.
>
> However, it looks to me that whenever I change parameters on the
> Tradesman entity JPA creates/persists for some reason the Tradesman in the
> DB, independently from the Company entity.
> I use Standard GWT settings: GWT 2.5, DataNucleus on Appengine
> Datastore.
>
> The scenario I am describing here is a standard scenario you will face
> when using GWT with JPA. I am surprised that my code is not working.
> @PrePersist works fine as long as the Entity is not in a owned
> relation with other entities.
>
> Does anyone has an idea what could be wrong here?
>
> Thank you!!
>
> Nermin
>
> @Thomas: Thank you for the advise. I will
>
> Am Dienstag, 21. Mai 2013 12:01:43 UTC+2 schrieb Juan Pablo Gardella:
>>
>> Update your entity as:
>>
>> @Entity
>> public class Tradesman extends User{
>> @ManyToOne(optional=false)
>> private Company company;
>>
>> *@PrePersist*
>> public void hashPassword(){
>> setPassword(BCrypt.hashpw(**enti**ty.getPassword(),
>> BCrypt.gensalt());
>> }
>>
>> And then check where are you persisting Tradesman without company.
>>
>>
>>
>> 2013/5/21 Thomas Broyer 
>>
>>>
>>>
>>> On Tuesday, May 21, 2013 11:18:42 AM UTC+2, Nermin wrote:

 Dear GWT developers,

 I have a "probably simple" problem with my application which I am
 obviously not abl

Re: JPA issue: A parent cannot be established or changed once an object has been persisted.

2013-05-23 Thread Nermin
Dear Juan,

For this purpose I use the GWT-s Request Factory.
However, in order to simplify the problem, I have created a server side 
persistence example using a simple servlet where one company and two users 
are created. Please have a look at the MyTestServlet.java within the Zip 
File.

https://dl.dropboxusercontent.com/u/2983671/JPA_Problem/JPA_Problem.zip

The funny thing is, I get now a different Eror:

javax.persistence.PersistenceException: Illegal argument

Caused by: java.lang.IllegalArgumentException: cross-group transaction need 
to be explicitly specified, see TransactionOptions.Builder.withXGfound both 
Element {
  type: "Tradesman"
  id: 361
}
 and Element {
  type: "Tradesman"
  id: 362
}

When I remove the @PrePersit from "User class" it works just fine!
The Error pops up as soon as i modify a parameter on "Tradesman" entity 
(more exactly on its parent class "User").

I really do not understand this behavior. ... I also must admit that I am 
not very advanced in JPA. 

Thank you for very much for your help.

Best regards:

Nermin


Am Mittwoch, 22. Mai 2013 15:28:50 UTC+2 schrieb Juan Pablo Gardella:
>
> Show how you are persisting the entities.
>
>
> 2013/5/22 Nermin >
>
>> Dear Alfredo and Juan,
>>
>> obviously there is an hidden problem with my code i simply do not see.
>> Could you please have a short look at these 3 classes (full code) and 
>> tell me what am I doing wrong here:
>>
>> https://dl.dropboxusercontent.com/u/2983671/JPA_Problem/JPA_Problem.zip
>>
>> Please note: Everything works fine as log as I do not try to make any 
>> changes to the Tradesman entity (its parameters).
>> When is set new password or any other parameter, i get an error message 
>> of type:
>>
>> Detected attempt to establish Company(no-id-yet) as the parent of 
>> Tradesman(358) but the entity identified by Tradesman(358) has already been 
>> persisted without a parent.  A parent cannot be established or changed once 
>> an object has been persisted.
>>
>> I am using: JPA with DataNucleus on Google Datastore. (Standard setting 
>> that come with GWT 2.5)
>>
>> Thank you in advance for your help!!
>>
>> Best regards:
>>
>> Nermin
>>
>>
>> Am Dienstag, 21. Mai 2013 18:29:54 UTC+2 schrieb Alfredo Quiroga-Villamil:
>>>
>>> Or use a cascade persist, merge to force creation or merge respectively
>>>
>>> Sent from my iPhone
>>>
>>> On May 21, 2013, at 7:02 AM, Juan Pablo Gardella  
>>> wrote:
>>>
>>> You should persist company before persist Tradesman or attach to an 
>>> existent company. This relation should be explicit. Create 
>>> company.addTrademan(Trademan t) method:
>>>
>>> company.addTrademan(Trademan t){
>>> users.add(t);
>>> t.setCompany(this);
>>> }
>>>
>>> Call this in a transactional method.
>>>
>>> Juan
>>>
>>>
>>>
>>>
>>>
>>>
>>> 2013/5/21 Nermin 
>>>
 Dear Juan,

 I tried *@ManyToOne(optional=false)*, unfortunately no changes.
 In my current setting, the @PrePersist is called only once. (I see it 
 on system out) That means: no multiple attempts to persist Tradesman 
 entity.

 However, it looks to me that whenever I change parameters on the 
 Tradesman entity JPA creates/persists for some reason the Tradesman in the 
 DB, independently from the Company entity.
 I use Standard GWT settings: GWT 2.5, DataNucleus on Appengine 
 Datastore.

 The scenario I am describing here is a standard scenario you will face 
 when using GWT with JPA. I am surprised that my code is not working.
 @PrePersist works fine as long as the Entity is not in a owned relation 
 with other entities.

 Does anyone has an idea what could be wrong here?

 Thank you!!

 Nermin

 @Thomas: Thank you for the advise. I will 

 Am Dienstag, 21. Mai 2013 12:01:43 UTC+2 schrieb Juan Pablo Gardella:
>
> Update your entity as: 
>
> @Entity
> public class Tradesman extends User{
> @ManyToOne(optional=false)
> private Company company;
>
> *@PrePersist*
> public void hashPassword(){
> setPassword(BCrypt.hashpw(**entity.getPassword(), 
> BCrypt.gensalt());
> }
>
> And then check where are you persisting Tradesman without company. 
>
>
>
> 2013/5/21 Thomas Broyer 
>
>>
>>
>> On Tuesday, May 21, 2013 11:18:42 AM UTC+2, Nermin wrote:
>>>
>>> Dear GWT developers,
>>>
>>> I have a "probably simple" problem with my application which I am 
>>> obviously not able to solve.
>>>
>>> Two Classes: Company, Tradesman
>>>
>>> @Entity
>>> public class Company {
>>> @OneToMany(cascade = CascadeType.ALL, mappedBy = "company")
>>> private List users = new ArrayList();
>>>
>>> 
>>> }
>>>
>>>
>>> @Entity
>>> public class Tradesman extends User{
>>> @ManyToOne
>>> private Company company;
>>>
>>> *@PrePersist*
>>

Re: JPA issue: A parent cannot be established or changed once an object has been persisted.

2013-05-22 Thread Juan Pablo Gardella
Show how you are persisting the entities.


2013/5/22 Nermin 

> Dear Alfredo and Juan,
>
> obviously there is an hidden problem with my code i simply do not see.
> Could you please have a short look at these 3 classes (full code) and tell
> me what am I doing wrong here:
>
> https://dl.dropboxusercontent.com/u/2983671/JPA_Problem/JPA_Problem.zip
>
> Please note: Everything works fine as log as I do not try to make any
> changes to the Tradesman entity (its parameters).
> When is set new password or any other parameter, i get an error message of
> type:
>
> Detected attempt to establish Company(no-id-yet) as the parent of
> Tradesman(358) but the entity identified by Tradesman(358) has already been
> persisted without a parent.  A parent cannot be established or changed once
> an object has been persisted.
>
> I am using: JPA with DataNucleus on Google Datastore. (Standard setting
> that come with GWT 2.5)
>
> Thank you in advance for your help!!
>
> Best regards:
>
> Nermin
>
>
> Am Dienstag, 21. Mai 2013 18:29:54 UTC+2 schrieb Alfredo Quiroga-Villamil:
>>
>> Or use a cascade persist, merge to force creation or merge respectively
>>
>> Sent from my iPhone
>>
>> On May 21, 2013, at 7:02 AM, Juan Pablo Gardella 
>> wrote:
>>
>> You should persist company before persist Tradesman or attach to an
>> existent company. This relation should be explicit. Create
>> company.addTrademan(Trademan t) method:
>>
>> company.addTrademan(Trademan t){
>> users.add(t);
>> t.setCompany(this);
>> }
>>
>> Call this in a transactional method.
>>
>> Juan
>>
>>
>>
>>
>>
>>
>> 2013/5/21 Nermin 
>>
>>> Dear Juan,
>>>
>>> I tried *@ManyToOne(optional=false)*, unfortunately no changes.
>>> In my current setting, the @PrePersist is called only once. (I see it on
>>> system out) That means: no multiple attempts to persist Tradesman entity.
>>>
>>> However, it looks to me that whenever I change parameters on the
>>> Tradesman entity JPA creates/persists for some reason the Tradesman in the
>>> DB, independently from the Company entity.
>>> I use Standard GWT settings: GWT 2.5, DataNucleus on Appengine Datastore.
>>>
>>> The scenario I am describing here is a standard scenario you will face
>>> when using GWT with JPA. I am surprised that my code is not working.
>>> @PrePersist works fine as long as the Entity is not in a owned relation
>>> with other entities.
>>>
>>> Does anyone has an idea what could be wrong here?
>>>
>>> Thank you!!
>>>
>>> Nermin
>>>
>>> @Thomas: Thank you for the advise. I will
>>>
>>> Am Dienstag, 21. Mai 2013 12:01:43 UTC+2 schrieb Juan Pablo Gardella:

 Update your entity as:

 @Entity
 public class Tradesman extends User{
 @ManyToOne(optional=false)
 private Company company;

 *@PrePersist*
 public void hashPassword(){
 setPassword(BCrypt.hashpw(**entity.getPassword(),
 BCrypt.gensalt());
 }

 And then check where are you persisting Tradesman without company.



 2013/5/21 Thomas Broyer 

>
>
> On Tuesday, May 21, 2013 11:18:42 AM UTC+2, Nermin wrote:
>>
>> Dear GWT developers,
>>
>> I have a "probably simple" problem with my application which I am
>> obviously not able to solve.
>>
>> Two Classes: Company, Tradesman
>>
>> @Entity
>> public class Company {
>> @OneToMany(cascade = CascadeType.ALL, mappedBy = "company")
>> private List users = new ArrayList();
>>
>> 
>> }
>>
>>
>> @Entity
>> public class Tradesman extends User{
>> @ManyToOne
>> private Company company;
>>
>> *@PrePersist*
>> public void hashPassword(){
>> setPassword(BCrypt.hashpw(**entity.getPassword(),
>> BCrypt.gensalt());
>> }
>>
>> *JSR 303 validation on GWT is activated.*
>>
>> Here is the *error message:
>> *Detected attempt to establish Company(no-id-yet) as the parent of
>> Tradesman(356) but the entity identified by Tradesman(356) has already 
>> been
>> persisted without a parent.  A parent cannot be established or changed 
>> once
>> an object has been persisted.
>>
>> My problem is obviously that when I change some parameters within the
>> Tradesman entity within the *@PrePersist* method, a new child entity
>> is created.
>> In case I do not touch any parameter, in the @PrePersist, everything
>> works fine.
>>
>> What am I doing wrong here?
>>
>
> You're not reaching the appropriate group ;-)
>
> I suppose you're using AppEngine (form what I know of JPA, I can't see
> a reason for that kind of message, unless you're using JPA on AppEngine),
> in which case you can ask for support on StackOverflow: https://**
> develop**ers.google.com/**appengine/**community
>
> --
> You received this message becaus

Re: JPA issue: A parent cannot be established or changed once an object has been persisted.

2013-05-22 Thread Nermin
Dear Alfredo and Juan,

obviously there is an hidden problem with my code i simply do not see.
Could you please have a short look at these 3 classes (full code) and tell 
me what am I doing wrong here:

https://dl.dropboxusercontent.com/u/2983671/JPA_Problem/JPA_Problem.zip

Please note: Everything works fine as log as I do not try to make any 
changes to the Tradesman entity (its parameters).
When is set new password or any other parameter, i get an error message of 
type:

Detected attempt to establish Company(no-id-yet) as the parent of 
Tradesman(358) but the entity identified by Tradesman(358) has already been 
persisted without a parent.  A parent cannot be established or changed once 
an object has been persisted.

I am using: JPA with DataNucleus on Google Datastore. (Standard setting 
that come with GWT 2.5)

Thank you in advance for your help!!

Best regards:

Nermin


Am Dienstag, 21. Mai 2013 18:29:54 UTC+2 schrieb Alfredo Quiroga-Villamil:
>
> Or use a cascade persist, merge to force creation or merge respectively
>
> Sent from my iPhone
>
> On May 21, 2013, at 7:02 AM, Juan Pablo Gardella 
> > 
> wrote:
>
> You should persist company before persist Tradesman or attach to an 
> existent company. This relation should be explicit. Create 
> company.addTrademan(Trademan t) method:
>
> company.addTrademan(Trademan t){
> users.add(t);
> t.setCompany(this);
> }
>
> Call this in a transactional method.
>
> Juan
>
>
>
>
>
>
> 2013/5/21 Nermin >
>
>> Dear Juan,
>>
>> I tried *@ManyToOne(optional=false)*, unfortunately no changes.
>> In my current setting, the @PrePersist is called only once. (I see it on 
>> system out) That means: no multiple attempts to persist Tradesman entity.
>>
>> However, it looks to me that whenever I change parameters on the 
>> Tradesman entity JPA creates/persists for some reason the Tradesman in the 
>> DB, independently from the Company entity.
>> I use Standard GWT settings: GWT 2.5, DataNucleus on Appengine Datastore.
>>
>> The scenario I am describing here is a standard scenario you will face 
>> when using GWT with JPA. I am surprised that my code is not working.
>> @PrePersist works fine as long as the Entity is not in a owned relation 
>> with other entities.
>>
>> Does anyone has an idea what could be wrong here?
>>
>> Thank you!!
>>
>> Nermin
>>
>> @Thomas: Thank you for the advise. I will 
>>
>> Am Dienstag, 21. Mai 2013 12:01:43 UTC+2 schrieb Juan Pablo Gardella:
>>>
>>> Update your entity as: 
>>>
>>> @Entity
>>> public class Tradesman extends User{
>>> @ManyToOne(optional=false)
>>> private Company company;
>>>
>>> *@PrePersist*
>>> public void hashPassword(){
>>> setPassword(BCrypt.hashpw(**enti**ty.getPassword(), 
>>> BCrypt.gensalt());
>>> }
>>>
>>> And then check where are you persisting Tradesman without company. 
>>>
>>>
>>>
>>> 2013/5/21 Thomas Broyer 
>>>


 On Tuesday, May 21, 2013 11:18:42 AM UTC+2, Nermin wrote:
>
> Dear GWT developers,
>
> I have a "probably simple" problem with my application which I am 
> obviously not able to solve.
>
> Two Classes: Company, Tradesman
>
> @Entity
> public class Company {
> @OneToMany(cascade = CascadeType.ALL, mappedBy = "company")
> private List users = new ArrayList();
>
> 
> }
>
>
> @Entity
> public class Tradesman extends User{
> @ManyToOne
> private Company company;
>
> *@PrePersist*
> public void hashPassword(){
> setPassword(BCrypt.hashpw(**enti**ty.getPassword(), 
> BCrypt.gensalt());
> }
>
> *JSR 303 validation on GWT is activated.*
>
> Here is the *error message:
> *Detected attempt to establish Company(no-id-yet) as the parent of 
> Tradesman(356) but the entity identified by Tradesman(356) has already 
> been 
> persisted without a parent.  A parent cannot be established or changed 
> once 
> an object has been persisted.
>
> My problem is obviously that when I change some parameters within the 
> Tradesman entity within the *@PrePersist* method, a new child entity 
> is created.
> In case I do not touch any parameter, in the @PrePersist, everything 
> works fine.
>
> What am I doing wrong here?
>

 You're not reaching the appropriate group ;-)

 I suppose you're using AppEngine (form what I know of JPA, I can't see 
 a reason for that kind of message, unless you're using JPA on AppEngine), 
 in which case you can ask for support on StackOverflow: https://**
 developers.google.com/**appengine/community
  
 -- 
 You received this message because you are subscribed to the Google 
 Groups "Google Web Toolkit" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to google-web-toolkit+**unsubscr...@googlegroup

Re: JPA issue: A parent cannot be established or changed once an object has been persisted.

2013-05-21 Thread Alfredo Quiroga
Or use a cascade persist, merge to force creation or merge respectively

Sent from my iPhone

On May 21, 2013, at 7:02 AM, Juan Pablo Gardella  
wrote:

> You should persist company before persist Tradesman or attach to an existent 
> company. This relation should be explicit. Create 
> company.addTrademan(Trademan t) method:
> 
> company.addTrademan(Trademan t){
> users.add(t);
> t.setCompany(this);
> }
> 
> Call this in a transactional method.
> 
> Juan
> 
> 
> 
> 
> 
> 
> 2013/5/21 Nermin 
>> Dear Juan,
>> 
>> I tried @ManyToOne(optional=false), unfortunately no changes.
>> In my current setting, the @PrePersist is called only once. (I see it on 
>> system out) That means: no multiple attempts to persist Tradesman entity.
>> 
>> However, it looks to me that whenever I change parameters on the Tradesman 
>> entity JPA creates/persists for some reason the Tradesman in the DB, 
>> independently from the Company entity.
>> I use Standard GWT settings: GWT 2.5, DataNucleus on Appengine Datastore.
>> 
>> The scenario I am describing here is a standard scenario you will face when 
>> using GWT with JPA. I am surprised that my code is not working.
>> @PrePersist works fine as long as the Entity is not in a owned relation with 
>> other entities.
>> 
>> Does anyone has an idea what could be wrong here?
>> 
>> Thank you!!
>> 
>> Nermin
>> 
>> @Thomas: Thank you for the advise. I will 
>> 
>> Am Dienstag, 21. Mai 2013 12:01:43 UTC+2 schrieb Juan Pablo Gardella:
>>> 
>>> Update your entity as: 
>>> 
>>> @Entity
>>> public class Tradesman extends User{
>>> @ManyToOne(optional=false)
>>> private Company company;
>>> 
>>> @PrePersist
>>> public void hashPassword(){
>>> setPassword(BCrypt.hashpw(entity.getPassword(), BCrypt.gensalt());
>>> }
>>> 
>>> And then check where are you persisting Tradesman without company. 
>>> 
>>> 
>>> 
>>> 2013/5/21 Thomas Broyer 
 
 
 On Tuesday, May 21, 2013 11:18:42 AM UTC+2, Nermin wrote:
> 
> Dear GWT developers,
> 
> I have a "probably simple" problem with my application which I am 
> obviously not able to solve.
> 
> Two Classes: Company, Tradesman
> 
> @Entity
> public class Company {
> @OneToMany(cascade = CascadeType.ALL, mappedBy = "company")
> private List users = new ArrayList();
> 
> 
> }
> 
> 
> @Entity
> public class Tradesman extends User{
> @ManyToOne
> private Company company;
> 
> @PrePersist
> public void hashPassword(){
> setPassword(BCrypt.hashpw(entity.getPassword(), BCrypt.gensalt());
> }
> 
> JSR 303 validation on GWT is activated.
> 
> Here is the error message:
> Detected attempt to establish Company(no-id-yet) as the parent of 
> Tradesman(356) but the entity identified by Tradesman(356) has already 
> been persisted without a parent.  A parent cannot be established or 
> changed once an object has been persisted.
> 
> My problem is obviously that when I change some parameters within the 
> Tradesman entity within the @PrePersist method, a new child entity is 
> created.
> In case I do not touch any parameter, in the @PrePersist, everything 
> works fine.
> 
> What am I doing wrong here?
 
 You're not reaching the appropriate group ;-)
 
 I suppose you're using AppEngine (form what I know of JPA, I can't see a 
 reason for that kind of message, unless you're using JPA on AppEngine), in 
 which case you can ask for support on StackOverflow: 
 https://developers.google.com/appengine/community
 -- 
 You received this message because you are subscribed to the Google Groups 
 "Google Web Toolkit" group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to google-web-toolkit+unsubscr...@googlegroups.com.
 To post to this group, send email to google-we...@googlegroups.com.
 Visit this group at 
 http://groups.google.com/group/google-web-toolkit?hl=en.
 For more options, visit https://groups.google.com/groups/opt_out.
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Google Web Toolkit" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to google-web-toolkit+unsubscr...@googlegroups.com.
>> To post to this group, send email to google-web-toolkit@googlegroups.com.
>> Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Google Web Toolkit" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to google-web-toolkit+unsubscr...@googlegroups.com.
> To post to this group, send email to google-web-toolkit@googlegroups.com.
> Visit this group

Re: JPA issue: A parent cannot be established or changed once an object has been persisted.

2013-05-21 Thread Juan Pablo Gardella
You should persist company before persist Tradesman or attach to an
existent company. This relation should be explicit. Create
company.addTrademan(Trademan t) method:

company.addTrademan(Trademan t){
users.add(t);
t.setCompany(this);
}

Call this in a transactional method.

Juan






2013/5/21 Nermin 

> Dear Juan,
>
> I tried *@ManyToOne(optional=false)*, unfortunately no changes.
> In my current setting, the @PrePersist is called only once. (I see it on
> system out) That means: no multiple attempts to persist Tradesman entity.
>
> However, it looks to me that whenever I change parameters on the Tradesman
> entity JPA creates/persists for some reason the Tradesman in the DB,
> independently from the Company entity.
> I use Standard GWT settings: GWT 2.5, DataNucleus on Appengine Datastore.
>
> The scenario I am describing here is a standard scenario you will face
> when using GWT with JPA. I am surprised that my code is not working.
> @PrePersist works fine as long as the Entity is not in a owned relation
> with other entities.
>
> Does anyone has an idea what could be wrong here?
>
> Thank you!!
>
> Nermin
>
> @Thomas: Thank you for the advise. I will
>
> Am Dienstag, 21. Mai 2013 12:01:43 UTC+2 schrieb Juan Pablo Gardella:
>>
>> Update your entity as:
>>
>> @Entity
>> public class Tradesman extends User{
>> @ManyToOne(optional=false)
>> private Company company;
>>
>> *@PrePersist*
>> public void hashPassword(){
>> setPassword(BCrypt.hashpw(**enti**ty.getPassword(),
>> BCrypt.gensalt());
>> }
>>
>> And then check where are you persisting Tradesman without company.
>>
>>
>>
>> 2013/5/21 Thomas Broyer 
>>
>>>
>>>
>>> On Tuesday, May 21, 2013 11:18:42 AM UTC+2, Nermin wrote:

 Dear GWT developers,

 I have a "probably simple" problem with my application which I am
 obviously not able to solve.

 Two Classes: Company, Tradesman

 @Entity
 public class Company {
 @OneToMany(cascade = CascadeType.ALL, mappedBy = "company")
 private List users = new ArrayList();

 
 }


 @Entity
 public class Tradesman extends User{
 @ManyToOne
 private Company company;

 *@PrePersist*
 public void hashPassword(){
 setPassword(BCrypt.hashpw(**enti**ty.getPassword(),
 BCrypt.gensalt());
 }

 *JSR 303 validation on GWT is activated.*

 Here is the *error message:
 *Detected attempt to establish Company(no-id-yet) as the parent of
 Tradesman(356) but the entity identified by Tradesman(356) has already been
 persisted without a parent.  A parent cannot be established or changed once
 an object has been persisted.

 My problem is obviously that when I change some parameters within the
 Tradesman entity within the *@PrePersist* method, a new child entity
 is created.
 In case I do not touch any parameter, in the @PrePersist, everything
 works fine.

 What am I doing wrong here?

>>>
>>> You're not reaching the appropriate group ;-)
>>>
>>> I suppose you're using AppEngine (form what I know of JPA, I can't see a
>>> reason for that kind of message, unless you're using JPA on AppEngine), in
>>> which case you can ask for support on StackOverflow: https://**
>>> developers.google.com/**appengine/community
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Google Web Toolkit" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to google-web-toolkit+**unsubscr...@googlegroups.com.
>>> To post to this group, send email to google-we...@**googlegroups.com.
>>> Visit this group at http://groups.google.com/**
>>> group/google-web-toolkit?hl=en
>>> **.
>>> For more options, visit 
>>> https://groups.google.com/**groups/opt_out
>>> .
>>>
>>>
>>>
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-web-toolkit+unsubscr...@googlegroups.com.
> To post to this group, send email to google-web-toolkit@googlegroups.com.
> Visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: JPA issue: A parent cannot be established or changed once an object has been persisted.

2013-05-21 Thread Nermin
Dear Juan,

I tried *@ManyToOne(optional=false)*, unfortunately no changes.
In my current setting, the @PrePersist is called only once. (I see it on 
system out) That means: no multiple attempts to persist Tradesman entity.

However, it looks to me that whenever I change parameters on the Tradesman 
entity JPA creates/persists for some reason the Tradesman in the DB, 
independently from the Company entity.
I use Standard GWT settings: GWT 2.5, DataNucleus on Appengine Datastore.

The scenario I am describing here is a standard scenario you will face when 
using GWT with JPA. I am surprised that my code is not working.
@PrePersist works fine as long as the Entity is not in a owned relation 
with other entities.

Does anyone has an idea what could be wrong here?

Thank you!!

Nermin

@Thomas: Thank you for the advise. I will 

Am Dienstag, 21. Mai 2013 12:01:43 UTC+2 schrieb Juan Pablo Gardella:
>
> Update your entity as: 
>
> @Entity
> public class Tradesman extends User{
> @ManyToOne(optional=false)
> private Company company;
>
> *@PrePersist*
> public void hashPassword(){
> setPassword(BCrypt.hashpw(**entity.getPassword(), 
> BCrypt.gensalt());
> }
>
> And then check where are you persisting Tradesman without company. 
>
>
>
> 2013/5/21 Thomas Broyer >
>
>>
>>
>> On Tuesday, May 21, 2013 11:18:42 AM UTC+2, Nermin wrote:
>>>
>>> Dear GWT developers,
>>>
>>> I have a "probably simple" problem with my application which I am 
>>> obviously not able to solve.
>>>
>>> Two Classes: Company, Tradesman
>>>
>>> @Entity
>>> public class Company {
>>> @OneToMany(cascade = CascadeType.ALL, mappedBy = "company")
>>> private List users = new ArrayList();
>>>
>>> 
>>> }
>>>
>>>
>>> @Entity
>>> public class Tradesman extends User{
>>> @ManyToOne
>>> private Company company;
>>>
>>> *@PrePersist*
>>> public void hashPassword(){
>>> setPassword(BCrypt.hashpw(**entity.getPassword(), 
>>> BCrypt.gensalt());
>>> }
>>>
>>> *JSR 303 validation on GWT is activated.*
>>>
>>> Here is the *error message:
>>> *Detected attempt to establish Company(no-id-yet) as the parent of 
>>> Tradesman(356) but the entity identified by Tradesman(356) has already been 
>>> persisted without a parent.  A parent cannot be established or changed once 
>>> an object has been persisted.
>>>
>>> My problem is obviously that when I change some parameters within the 
>>> Tradesman entity within the *@PrePersist* method, a new child entity is 
>>> created.
>>> In case I do not touch any parameter, in the @PrePersist, everything 
>>> works fine.
>>>
>>> What am I doing wrong here?
>>>
>>
>> You're not reaching the appropriate group ;-)
>>
>> I suppose you're using AppEngine (form what I know of JPA, I can't see a 
>> reason for that kind of message, unless you're using JPA on AppEngine), in 
>> which case you can ask for support on StackOverflow: 
>> https://developers.google.com/appengine/community
>>  
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Google Web Toolkit" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to google-web-toolkit+unsubscr...@googlegroups.com .
>> To post to this group, send email to 
>> google-we...@googlegroups.com
>> .
>> Visit this group at 
>> http://groups.google.com/group/google-web-toolkit?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: JPA issue: A parent cannot be established or changed once an object has been persisted.

2013-05-21 Thread Juan Pablo Gardella
Update your entity as:

@Entity
public class Tradesman extends User{
@ManyToOne(optional=false)
private Company company;

*@PrePersist*
public void hashPassword(){
setPassword(BCrypt.hashpw(**entity.getPassword(), BCrypt.gensalt());
}

And then check where are you persisting Tradesman without company.



2013/5/21 Thomas Broyer 

>
>
> On Tuesday, May 21, 2013 11:18:42 AM UTC+2, Nermin wrote:
>>
>> Dear GWT developers,
>>
>> I have a "probably simple" problem with my application which I am
>> obviously not able to solve.
>>
>> Two Classes: Company, Tradesman
>>
>> @Entity
>> public class Company {
>> @OneToMany(cascade = CascadeType.ALL, mappedBy = "company")
>> private List users = new ArrayList();
>>
>> 
>> }
>>
>>
>> @Entity
>> public class Tradesman extends User{
>> @ManyToOne
>> private Company company;
>>
>> *@PrePersist*
>> public void hashPassword(){
>> setPassword(BCrypt.hashpw(**entity.getPassword(),
>> BCrypt.gensalt());
>> }
>>
>> *JSR 303 validation on GWT is activated.*
>>
>> Here is the *error message:
>> *Detected attempt to establish Company(no-id-yet) as the parent of
>> Tradesman(356) but the entity identified by Tradesman(356) has already been
>> persisted without a parent.  A parent cannot be established or changed once
>> an object has been persisted.
>>
>> My problem is obviously that when I change some parameters within the
>> Tradesman entity within the *@PrePersist* method, a new child entity is
>> created.
>> In case I do not touch any parameter, in the @PrePersist, everything
>> works fine.
>>
>> What am I doing wrong here?
>>
>
> You're not reaching the appropriate group ;-)
>
> I suppose you're using AppEngine (form what I know of JPA, I can't see a
> reason for that kind of message, unless you're using JPA on AppEngine), in
> which case you can ask for support on StackOverflow:
> https://developers.google.com/appengine/community
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-web-toolkit+unsubscr...@googlegroups.com.
> To post to this group, send email to google-web-toolkit@googlegroups.com.
> Visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: JPA issue: A parent cannot be established or changed once an object has been persisted.

2013-05-21 Thread Thomas Broyer


On Tuesday, May 21, 2013 11:18:42 AM UTC+2, Nermin wrote:
>
> Dear GWT developers,
>
> I have a "probably simple" problem with my application which I am 
> obviously not able to solve.
>
> Two Classes: Company, Tradesman
>
> @Entity
> public class Company {
> @OneToMany(cascade = CascadeType.ALL, mappedBy = "company")
> private List users = new ArrayList();
>
> 
> }
>
>
> @Entity
> public class Tradesman extends User{
> @ManyToOne
> private Company company;
>
> *@PrePersist*
> public void hashPassword(){
> setPassword(BCrypt.hashpw(entity.getPassword(), BCrypt.gensalt());
> }
>
> *JSR 303 validation on GWT is activated.*
>
> Here is the *error message:
> *Detected attempt to establish Company(no-id-yet) as the parent of 
> Tradesman(356) but the entity identified by Tradesman(356) has already been 
> persisted without a parent.  A parent cannot be established or changed once 
> an object has been persisted.
>
> My problem is obviously that when I change some parameters within the 
> Tradesman entity within the *@PrePersist* method, a new child entity is 
> created.
> In case I do not touch any parameter, in the @PrePersist, everything works 
> fine.
>
> What am I doing wrong here?
>

You're not reaching the appropriate group ;-)

I suppose you're using AppEngine (form what I know of JPA, I can't see a 
reason for that kind of message, unless you're using JPA on AppEngine), in 
which case you can ask for support on StackOverflow: 
https://developers.google.com/appengine/community

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




JPA issue: A parent cannot be established or changed once an object has been persisted.

2013-05-21 Thread Nermin
Dear GWT developers,

I have a "probably simple" problem with my application which I am obviously 
not able to solve.

Two Classes: Company, Tradesman

@Entity
public class Company {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "company")
private List users = new ArrayList();


}


@Entity
public class Tradesman extends User{
@ManyToOne
private Company company;

*@PrePersist*
public void hashPassword(){
setPassword(BCrypt.hashpw(entity.getPassword(), BCrypt.gensalt());
}

*JSR 303 validation on GWT is activated.*

Here is the *error message:
*Detected attempt to establish Company(no-id-yet) as the parent of 
Tradesman(356) but the entity identified by Tradesman(356) has already been 
persisted without a parent.  A parent cannot be established or changed once 
an object has been persisted.

My problem is obviously that when I change some parameters within the 
Tradesman entity within the *@PrePersist* method, a new child entity is 
created.
In case I do not touch any parameter, in the @PrePersist, everything works 
fine.

What am I doing wrong here?

Thank you in advance:

Nermin

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.