openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sandhya (JIRA)" <>
Subject [jira] Created: (OPENJPA-792) An entity persist may fail when @MappedSupercalss is specified.
Date Wed, 26 Nov 2008 19:16:44 GMT
An entity persist may fail when @MappedSupercalss is specified. 

                 Key: OPENJPA-792
             Project: OpenJPA
          Issue Type: Bug
            Reporter: Sandhya

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

import java.util.Date;

import javax.persistence.Id;
import javax.persistence.Column;

public class Party {
    protected Long PartyId;
    protected String Status;
    protected String ArchiveStatus;
    protected Date CreateDate;
    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;
    public String getStatus() {
        return this.Status;
    public String getArchiveStatus() {
        return this.ArchiveStatus;
    public void setCreateDate(Date d) {
        this.CreateDate = d;
    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;

@Table(name = "Site")
 public class Site  extends Party implements {

       private static final long serialVersionUID = 1L;
       private String SiteName;
       private String SiteDescription;
     /*  private List<Store> stores;
       @OneToMany(mappedBy="site",  cascade=CascadeType.ALL, fetch=FetchType.LAZY, 
       public List<Store> getStores() {
             return stores;
      public void setStores(List<Store> 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;

@Table(name = "Store")
 public class Store extends Party implements {

       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, 
       @JoinColumn(name = "Store.SiteId",
       referencedColumnName="site.PartyId", nullable = false, insertable = true,
       updatable = true)
       public Site getSite() {
             return site;
       public void setSite(Site s) {
  = 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");
        System.out.println("Done creating Site");
        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();
        Site s = new Site();
        s.setSiteName("San Jose");
        s.setSiteDescription("San Jose site");
        s.setCreateDate(new Date());
    public static void createStore() {
        EntityManager em = emf.createEntityManager();
         Site site = em.find(Site.class, pkey);
          Store store = new Store();
          store.setCreateDate(new Date());
       //  List<Store> stores = new ArrayList<Store>();
        //  stores.add(store);
       //   site.setStores(stores);



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" <openjpa-2.0.0-SNAPSHOT-runknown nonfatal store error> 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(
	at org.apache.openjpa.kernel.BrokerImpl.persist(
	at org.apache.openjpa.kernel.BrokerImpl.persist(
	at org.apache.openjpa.kernel.DelegatingBroker.persist(
	at org.apache.openjpa.persistence.EntityManagerImpl.persist(
	at lazy_fetch.tests.TestLazyFetch.createStore(
	at lazy_fetch.tests.TestLazyFetch.main(

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message