From dev-return-7835-apmail-openjpa-dev-archive=openjpa.apache.org@openjpa.apache.org Mon Apr 14 13:53:21 2008 Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 33082 invoked from network); 14 Apr 2008 13:53:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 14 Apr 2008 13:53:21 -0000 Received: (qmail 38501 invoked by uid 500); 14 Apr 2008 13:53:21 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 38478 invoked by uid 500); 14 Apr 2008 13:53:21 -0000 Mailing-List: contact dev-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list dev@openjpa.apache.org Received: (qmail 38469 invoked by uid 99); 14 Apr 2008 13:53:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Apr 2008 06:53:21 -0700 X-ASF-Spam-Status: No, hits=-2.0 required=10.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of swaggon@us.ibm.com designates 32.97.110.152 as permitted sender) Received: from [32.97.110.152] (HELO e34.co.us.ibm.com) (32.97.110.152) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Apr 2008 13:52:27 +0000 Received: from d03relay02.boulder.ibm.com (d03relay02.boulder.ibm.com [9.17.195.227]) by e34.co.us.ibm.com (8.13.8/8.13.8) with ESMTP id m3EDoeTR029786 for ; Mon, 14 Apr 2008 09:50:40 -0400 Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by d03relay02.boulder.ibm.com (8.13.8/8.13.8/NCO v8.7) with ESMTP id m3EDqkuC107504 for ; Mon, 14 Apr 2008 07:52:46 -0600 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id m3EDqkvG028798 for ; Mon, 14 Apr 2008 07:52:46 -0600 Received: from d03nm130.boulder.ibm.com (d03nm130.boulder.ibm.com [9.17.195.174]) by d03av01.boulder.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id m3EDqkXj028795 for ; Mon, 14 Apr 2008 07:52:46 -0600 To: dev@openjpa.apache.org MIME-Version: 1.0 Subject: Can't null out entity attributes when openjpa.DetachState set to loaded X-Mailer: Lotus Notes Release 7.0 HF277 June 21, 2006 From: Sara H Waggoner Message-ID: Date: Mon, 14 Apr 2008 09:52:35 -0400 X-MIMETrack: Serialize by Router on D03NM130/03/M/IBM(Release 7.0.2FP2HF300 | September 14, 2007) at 04/14/2008 07:52:46, Serialize complete at 04/14/2008 07:52:46 Content-Type: multipart/alternative; boundary="=_alternative 004C2C8B8525742B_=" X-Virus-Checked: Checked by ClamAV on apache.org --=_alternative 004C2C8B8525742B_= Content-Type: text/plain; charset="US-ASCII" Hi, I have some code that creates an entity, sets all attributes to non-null values, persists the entity, then sets all attributes to null and merges the entity. When I run this code, the persist works fine but the merge does not - the attributes that were nulled out in the merged entity still exist with their original values in the database record. Here is the code: persistence.xml: org.apache.openjpa.persistence.PersistenceProviderImpl net.iss.mss.jparef.services.entitynulls.Item net.iss.mss.jparef.services.entitynulls.Photo Item.java: package net.iss.mss.jparef.services.entitynulls; import java.io.*; import javax.persistence.*; @Entity @Table(name = "item") public class Item implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "item_id") private int id; @Column(name="title") private String title; @OneToOne(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.REMOVE}) @JoinColumn(name="photo_id", referencedColumnName="photo_id") private Photo photo; public int getId () { return id; } public void setId (int id) { this.id = id; } public String getTitle () { return title; } public void setTitle (String title) { this.title = title; } public Photo getPhoto () { return photo; } public void setPhoto (Photo photo) { this.photo = photo; } } Photo.java package net.iss.mss.jparef.services.entitynulls; import java.io.*; import javax.persistence.*; @SuppressWarnings({"JpaDataSourceORMInspection"}) @Entity @Table(name = "photo") public class Photo implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "photo_id") private int id; @Column(name = "bytes") @Lob private Byte[] bytes; @OneToOne(mappedBy = "photo") private Item item; public int getId () { return id; } public void setId (int id) { this.id = id; } public Byte[] getBytes () { return bytes; } public void setBytes (Byte[] bytes) { this.bytes = bytes; } public Item getItem () { return item; } public void setItem (Item item) { this.item = item; } } TestNulls.java import java.sql.Connection; import javax.persistence.*; import junit.framework.*; import org.apache.openjpa.persistence.*; import net.iss.mss.jparef.services.entitynulls.*; import net.iss.mss.jpa.*; public class TestNulls extends TestCase { private JpaContext context = new JpaContext ("spring-artMuseumServices.xml"); public void test () throws Exception { EntityManager em = null; try { // Create new item, set properties and object reference (photo), and persist em = context.getEmf().createEntityManager (); Item item = new Item(); item.setTitle("Title 1"); Byte[] bytes = {1, 2, 3}; Photo photo = new Photo(); photo.setBytes(bytes); item.setPhoto(photo); photo.setItem(item); em.getTransaction().begin(); em.persist(item); em.getTransaction().commit(); em.close (); // Null out item properties and object reference, then merge em = context.getEmf().createEntityManager (); item.setTitle(null); item.setPhoto(null); photo.setItem(null); em.getTransaction().begin(); em.merge(item); em.getTransaction().commit(); em.close (); } catch (Exception e) { throw e; } finally { try { em.close (); context.close (); } catch (Exception e) { //Ignore } } } } Thanks, Sara --=_alternative 004C2C8B8525742B_=--