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 
> <gardella...@gmail.com<javascript:>> 
> 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 <use...@gmx.de <javascript:>>
>
>> 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 <t.br...@gmail.com>
>>>
>>>>
>>>>
>>>> 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<Tradesman> users = new ArrayList<Tradesman>();
>>>>>
>>>>> ....
>>>>> }
>>>>>
>>>>>
>>>>> @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<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<http://groups.google.com/group/google-web-toolkit?hl=en>
>>>> **.
>>>> For more options, visit 
>>>> https://groups.google.com/**groups/opt_out<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 <javascript:>.
>> To post to this group, send email to 
>> google-we...@googlegroups.com<javascript:>
>> .
>> 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 <javascript:>.
> To post to this group, send email to 
> google-we...@googlegroups.com<javascript:>
> .
> 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.


Reply via email to