Hi Michael,

your assumptions are correct. 


After em.persist(e); I get this exception if I specify CascadeType.PERSIST:

>org.apache.openjpa.persistence.InvalidStateException: The generated value
> processing detected an existing value assigned to this field:
> mypackage.Department.idDepartment.  This existing value was either
> provided
> via an initializer or by calling the setter method.  You either need to
> remove the @GeneratedValue annotation or modify the code to remove the
> initializer processing. 

because id in referenced object has an annotation
@GeneratedValue(strategy=GenerationType.IDENTITY)  and that is something I
cannot and don't want to change.

If I don't specify CascadeType.PERSIST, I get this error:

> <openjpa-1.0.2-r420667:627158 nonfatal user error>
> org.apache.openjpa.persistence.InvalidStateException: Encountered
> unmanaged object "[EMAIL PROTECTED]" in persistent field
> "mypackage.Employee.idDepartment" of managed object
> "mypackage.Employee-5" during flush.  However, this field does not allow
> to be CascadeType.PERSIST.  You cannot flush unmanaged objects. 


Michael Dick wrote:
> 
> Hi Anonimus,
> 
> What exception do you get when you don't specify CascadeType.PERSIST?
> 
> I'm assuming you're doing something like this :
> 
> Employee e = new Employe();
> e.setName("John Doe");
> 
> Department d = em.find(Department.class, idDept);  // this is what I think
> you mean by loading all the references.
> e.setIdDepartment(d);
> 
> Rank r = em.find(Rank.class, idRank);
> e.setIdRank(r);
> 
> // and so on
> 
> em.persist(e);
> 
> If that's the case then you shouldn't get any exceptions.
> 
> Thanks,
> 
> -Mike
> 
> On Wed, Jun 11, 2008 at 8:52 AM, Anonimus <[EMAIL PROTECTED]> wrote:
> 
>>
>>
>> Ognjen Blagojevic wrote:
>> >
>> > It must be a way to INSERT objects in the database without looking up
>> > for all the references, but I am not able to find it.
>> >
>>
>> My problem is similar as yours, with a single difference.
>> I don't mind loading all the references because I need them in the
>> program.
>> But I don't know how to insert object and disable an attempt of inserting
>> in
>> related tables. If I put cascade = cascadeType.PERSIST, I get an
>> exception
>> (as you do). If I don't put cascade = cascadeType.PERSIST (which is
>> logical), I get an exception. Since I'm new in JPA, I'm quite lost now.
>>
>> --
>> View this message in context:
>> http://www.nabble.com/How-to-PERSIST-object-without-loading-references--tp16472647p17778155.html
>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-PERSIST-object-without-loading-references--tp16472647p17787968.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to