From dev-return-12577-apmail-openjpa-dev-archive=openjpa.apache.org@openjpa.apache.org Fri Jun 26 11:35:22 2009 Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 98662 invoked from network); 26 Jun 2009 11:35:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 26 Jun 2009 11:35:22 -0000 Received: (qmail 29354 invoked by uid 500); 26 Jun 2009 11:35:33 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 29315 invoked by uid 500); 26 Jun 2009 11:35:33 -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 29304 invoked by uid 99); 26 Jun 2009 11:35:32 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Jun 2009 11:35:32 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Jun 2009 11:35:28 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 9815D234C004 for ; Fri, 26 Jun 2009 04:35:07 -0700 (PDT) Message-ID: <437283750.1246016107614.JavaMail.jira@brutus> Date: Fri, 26 Jun 2009 04:35:07 -0700 (PDT) From: "Donald Woods (JIRA)" To: dev@openjpa.apache.org Subject: [jira] Commented: (OPENJPA-792) An entity persist may fail when @MappedSupercalss is specified. In-Reply-To: <322145061.1227727004291.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/OPENJPA-792?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12724481#action_12724481 ] Donald Woods commented on OPENJPA-792: -------------------------------------- Neither 1.3.0 nor 2.0.0 have been released yet. You can download the assembly from the latest nightly build of 1.3.0-SNAPSHOT from - http://people.apache.org/repo/m2-snapshot-repository/org/apache/openjpa/apache-openjpa/1.3.0-SNAPSHOT/ Or the latest 2.0.0-SNAPSHOT build from - http://people.apache.org/repo/m2-snapshot-repository/org/apache/openjpa/apache-openjpa/2.0.0-SNAPSHOT/ > An entity persist may fail when @MappedSupercalss is specified. > ---------------------------------------------------------------- > > Key: OPENJPA-792 > URL: https://issues.apache.org/jira/browse/OPENJPA-792 > Project: OpenJPA > Issue Type: Bug > Components: jpa > Affects Versions: 2.0.0-M2 > Reporter: Sandhya > Fix For: 1.3.0, 2.0.0-M2 > > Attachments: openjpa-792.patch > > > When @MappedSuperClass annotation is specified and if we try to persist the same key of the subclasses which are entities of the Mappedsuperclass , Persist fails which is not the expected behavior. > import java.util.Date; > import javax.persistence.Id; > import javax.persistence.Column; > @javax.persistence.MappedSuperclass > public class Party { > > > protected Long PartyId; > protected String Status; > protected String ArchiveStatus; > protected Date CreateDate; > > @Id > public Long getPartyId() { > return this.PartyId; > } > > public void setPartyId(Long id){ > this.PartyId = id; > } > > public void setArchiveStatus(String s){ > this.ArchiveStatus = s; > > } > > public void setStatus(String s) { > this.Status = s; > } > > @Column > public String getStatus() { > return this.Status; > } > > @Column > public String getArchiveStatus() { > return this.ArchiveStatus; > } > > public void setCreateDate(Date d) { > this.CreateDate = d; > } > > @Column > public Date getCreateDate() { > return this.CreateDate; > } > } > import java.util.List; > import javax.persistence.DiscriminatorValue; > import javax.persistence.Entity; > import javax.persistence.Inheritance; > import javax.persistence.OneToMany; > import javax.persistence.Table; > import javax.persistence.FetchType; > import javax.persistence.CascadeType; > import javax.persistence.InheritanceType; > import org.apache.openjpa.persistence.jdbc.DiscriminatorStrategy; > @Entity > @Table(name = "Site") > public class Site extends Party implements java.io.Serializable { > private static final long serialVersionUID = 1L; > > private String SiteName; > private String SiteDescription; > /* private List stores; > > @OneToMany(mappedBy="site", cascade=CascadeType.ALL, fetch=FetchType.LAZY, > targetEntity=Store.class) > public List getStores() { > return stores; > } > > public void setStores(List storeList){ > this.stores = storeList; > }*/ > public void setSiteName(String s) { > this.SiteName = s; > } > > public String getSiteName(){ > return this.SiteName; > } > > public void setSiteDescription(String s) { > this.SiteDescription = s; > } > > public String getSiteDescription() { > return this.SiteDescription; > } > } > import javax.persistence.CascadeType; > import javax.persistence.Entity; > import javax.persistence.FetchType; > import javax.persistence.Inheritance; > import javax.persistence.InheritanceType; > import javax.persistence.JoinColumn; > import javax.persistence.ManyToOne; > import javax.persistence.Table; > @Entity > @Table(name = "Store") > public class Store extends Party implements java.io.Serializable { > private static final long serialVersionUID = 1L; > private String StoreName; > private String StoreDescription; > > private Site site; > private Long SiteId; > > @ManyToOne( fetch = FetchType.LAZY, cascade = CascadeType.ALL, > targetEntity=Site.class) > @JoinColumn(name = "Store.SiteId", > referencedColumnName="site.PartyId", nullable = false, insertable = true, > updatable = true) > > public Site getSite() { > return site; > } > > public void setSite(Site s) { > this.site = s; > > } > > public void setStoreName(String s) { > this.StoreName = s; > } > > public String getStoreName() { > return this.StoreName; > } > > public void setStoreDescription(String s){ > this.StoreDescription = s; > } > > public String getStoreDescription(){ > return this.StoreDescription; > } > > > public void setSiteId(Long id) { > this.SiteId = id; > } > > public Long getSiteId() { > return this.SiteId; > } > > } > TestCase follows: > import java.util.ArrayList; > import java.util.Date; > import java.util.List; > import javax.persistence.EntityManager; > import javax.persistence.EntityManagerFactory; > import javax.persistence.Persistence; > import lazy_fetch.bean.Site; > import lazy_fetch.bean.Store; > public class TestLazyFetch { > > public static EntityManagerFactory emf = null; > public static Long pkey = new Long (1502); > > public static void main(String[] args) { > > emf = Persistence.createEntityManagerFactory("LazyFetch"); > > createSite(); > System.out.println("Done creating Site"); > createStore(); > System.out.println("Done creating Store"); > // getStoreWithSite(); > > } > > public static void getStoreWithSite() { > EntityManager em = emf.createEntityManager(); > Store store = em.find(Store.class, pkey); > System.out.println("store =" + store); > // Site site = store.getSite(); > // System.out.println("site =" + site); > } > > public static void createSite() { > EntityManager em = emf.createEntityManager(); > em.getTransaction().begin(); > > Site s = new Site(); > s.setPartyId(pkey); > s.setSiteName("San Jose"); > s.setSiteDescription("San Jose site"); > s.setStatus("2"); > s.setArchiveStatus("2"); > s.setCreateDate(new Date()); > > em.persist(s); > em.getTransaction().commit(); > em.close(); > } > > public static void createStore() { > > EntityManager em = emf.createEntityManager(); > em.getTransaction().begin(); > > Site site = em.find(Site.class, pkey); > > Store store = new Store(); > store.setPartyId(pkey); > store.setStoreDescription("storeDescription"); > store.setStoreName("storeName"); > store.setStatus("1"); > store.setArchiveStatus("1"); > store.setCreateDate(new Date()); > store.setSiteId(site.getPartyId()); > store.setSite(site); > > // List stores = new ArrayList(); > // stores.add(store); > // site.setStores(stores); > em.persist(store); > em.getTransaction().commit(); > } > > } > 47 LazyFetch INFO [main] openjpa.Runtime - Starting OpenJPA 2.0.0-SNAPSHOT > 125 LazyFetch INFO [main] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.DB2Dictionary". > Exception in thread "main" org.apache.openjpa.persistence.EntityExistsException: An object of type "lazy_fetch.bean.Store" with oid "lazy_fetch.bean.Party-1502" already exists in this context; another cannot be persisted. > FailedObject: lazy_fetch.bean.Store@9c609c6 > at org.apache.openjpa.kernel.BrokerImpl.checkForDuplicateId(BrokerImpl.java:4756) > at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2445) > at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2281) > at org.apache.openjpa.kernel.DelegatingBroker.persist(DelegatingBroker.java:1021) > at org.apache.openjpa.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:645) > at lazy_fetch.tests.TestLazyFetch.createStore(TestLazyFetch.java:77) > at lazy_fetch.tests.TestLazyFetch.main(TestLazyFetch.java:25) -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.