persistence@glassfish.java.net

Re: Urgent: "Can not PERSIST detatched object" exception

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Tue, 14 Feb 2006 12:57:23 -0800

Thanks!

Ian,

The CMPOrder has this line in LineItemBean.ejbCreate
        setItemId(order.getNextId());

regards,
-marina

Christopher Delahunt wrote:
> Hello Ian,
>
> You haven't set the full pk for the LineItem. In
> RequestBean.addLineItem(), you have:
>
> LineItem lineItem = new LineItem(order, quantity, part.getVendorPart());
>
> Which:
> public LineItem(Order order, int quantity, VendorPart vendorPart) {
> this.order = order;
> this.orderId = order.getOrderId();
> this.quantity = quantity;
> this.vendorPart = vendorPart;
> }
>
> But you have a composite PK of orderId and itemId. So the second time
> you try to call this method with the same Order object, you get a second
> LineItem with the same pk (orderId=x, itemId=null) as the first LineItem
> - a detached entity.
>
>
> Best Regards,
> Chris
>
> ----- Original Message ----- From: "Ian Evans" <Ian.Evans_at_Sun.COM>
> To: <persistence_at_glassfish.dev.java.net>
> Sent: Tuesday, February 14, 2006 3:26 PM
> Subject: Urgent: "Can not PERSIST detatched object" exception
>
>
>> I'm working on the Persistence examples for the Java EE 5 Tutorial, and
>> am running into an exception for which I can't find the cause. The
>> example is a port of the 1.4 cmporder example.
>>
>> I'm getting a "Can not PERSIST detatched object" exception when adding a
>> LineItem to an Order. It happens when I attempt to add a second LineItem
>> to an Order.
>>
>> The example is for AppServer 9 PE beta (build b32g), so that's what I'm
>> running the app on. The beta is next week, so any help is greatly
>> appreciated.
>>
>> I've attached a tar.gz file containing the source, with the necessary
>> build files. To build the example:
>> 1. Set javaee.home in common/build.properties.
>> 2. Set the admin password in common/admin-password.txt.
>> 3. Create the tables in Derby by running:
>> % cd ejb/order
>> % ant create-db_common
>> The SQL source is in common/sql/derby/tutorial.sql.
>> 4. Run the 'all' target to build, package, and deploy the app.
>> % ant all
>>
>> I've also attached the EAR.
>>
>> The exception is thrown when the lineItem is added to order in
>> order.request.RequestBean.addLineItem().
>>
>> -i
>> --
>> Ian Evans
>> ian dot evans at sun dot com
>> Java Enterprise Edition technical documentation
>>