Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 26071 invoked from network); 7 Jul 2010 15:11:45 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 7 Jul 2010 15:11:45 -0000 Received: (qmail 3678 invoked by uid 500); 7 Jul 2010 15:11:45 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 3651 invoked by uid 500); 7 Jul 2010 15:11:44 -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 3643 invoked by uid 99); 7 Jul 2010 15:11:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Jul 2010 15:11:44 +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.22] (HELO thor.apache.org) (140.211.11.22) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Jul 2010 15:11:41 +0000 Received: from thor (localhost [127.0.0.1]) by thor.apache.org (8.13.8+Sun/8.13.8) with ESMTP id o67F3nN4001855 for ; Wed, 7 Jul 2010 15:03:49 GMT Message-ID: <21295425.240111278515029472.JavaMail.jira@thor> Date: Wed, 7 Jul 2010 11:03:49 -0400 (EDT) From: "Peter Rademaker (JIRA)" To: dev@openjpa.apache.org Subject: [jira] Updated: (OPENJPA-1718) multiple @OneToMany relations with entities with common super type using InheritanceType.JOINED are incorrectly fetched In-Reply-To: <356417.240091278514910182.JavaMail.jira@thor> 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-1718?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Peter Rademaker updated OPENJPA-1718: ------------------------------------- Description: I have an entity "Event" which has two @OneToMany relations with two entities "Appointment" and "Activity" which both have the same superclass "Booking". After saving an Event with 1 Activity and 1 Appointment and retrieving it using find, the Event is returned with 2 (!) Activities and 1 Appointment. One of these Activities seems to contain the data of the Appointment. I noticed that two things both seem to make it work as excepted: (1) change the @Inheritance strategy to one of InheritanceType.SINGLE_TABLE or InheritanceType.TABLE_PER_CLASS (2) remove the @Version field from "Event" These are the entity configurations: @Entity public final class Event { @Id @GeneratedValue protected Long id; @Version protected Integer version; @OneToMany(cascade = ALL, mappedBy = "event", fetch = FetchType.EAGER) private List activities = new ArrayList(); @OneToMany(cascade = ALL, mappedBy = "event", fetch = FetchType.EAGER) private List appointments = new ArrayList(); ... } @Entity @Inheritance(strategy = InheritanceType.JOINED) public class Booking { @Id @GeneratedValue protected Long id; @ManyToOne(optional = true, cascade = ALL, fetch = FetchType.EAGER) protected Event event; @Basic(fetch = FetchType.EAGER) public String name; ... } @Entity public final class Activity extends Booking { ... } @Entity public final class Appointment extends Booking { ... } This is the "test" which illustrates the problem: public static void main(String[] args) { Event event = new Event(); Appointment appointment = new Appointment("APPOINTMENT"); appointment.setEvent(event); event.addAppointment(appointment); Activity activity = new Activity("ACTIVITY"); activity.setEvent(event); event.addActivity(activity); System.out.println("#activities before saving: " + event.getActivities().size()); System.out.println("#appointments before saving: " + event.getAppointments().size()); Event saved = save(event); System.out.println("#activities after saving: " + saved.getActivities().size()); System.out.println("#appointments after saving: " + saved.getAppointments().size()); Event found = find(saved.getId()); System.out.println("#activities after find: " + found.getActivities().size()); System.out.println("#appointments after find: " + found.getAppointments().size()); } private static Event save(Event entity) { entityManager.getTransaction().begin(); Event result = entityManager.merge(entity); entityManager.getTransaction().commit(); return result; } private static Event find(long id) { entityManager.getTransaction().begin(); Event result = entityManager.find(Event.class, id); entityManager.getTransaction().commit(); return result; } static OpenJPAEntityManager entityManager = (OpenJPAEntityManager) Persistence.createEntityManagerFactory( "openjpa_test", System.getProperties()).createEntityManager(); I've attached all the files in a zip. was: I have an entity "Event" which has two @OneToMany relations with two entities "Appointment" and "Activity" which both have the same superclass "Booking". After saving an Event with 1 Activity and 1 Appointment and retrieving it using find, the Event is returned with 2 (!) Activities and 1 Appointment. One of these Activities seems to contain the data of the Appointment. I noticed that two things both seem to make it work as excepted: (1) change the @Inheritance strategy to one of InheritanceType.SINGLE_TABLE or InheritanceType.TABLE_PER_CLASS (2) remove the @Version field from "Event" These are the entity configurations: @Entity public final class Event { @Id @GeneratedValue protected Long id; @Version protected Integer version; @OneToMany(cascade = ALL, mappedBy = "event", fetch = FetchType.EAGER) private List activities = new ArrayList(); @OneToMany(cascade = ALL, mappedBy = "event", fetch = FetchType.EAGER) private List appointments = new ArrayList(); ... } @Entity @Inheritance(strategy = InheritanceType.JOINED) public class Booking { @Id @GeneratedValue protected Long id; @ManyToOne(optional = true, cascade = ALL, fetch = FetchType.EAGER) protected Event event; @Basic(fetch = FetchType.EAGER) public String name; ... } @Entity public final class Activity extends Booking { ... } @Entity public final class Appointment extends Booking { ... } This is the "test" which illustrates the problem: public static void main(String[] args) { Event event = new Event(); Appointment appointment = new Appointment("APPOINTMENT"); appointment.setEvent(event); event.addAppointment(appointment); Activity activity = new Activity("ACTIVITY"); activity.setEvent(event); event.addActivity(activity); System.out.println("#activities before saving: " + event.getActivities().size()); System.out.println("#appointments before saving: " + event.getAppointments().size()); Event saved = save(event); System.out.println("#activities after saving: " + saved.getActivities().size()); System.out.println("#appointments after saving: " + saved.getAppointments().size()); Event found = find(saved.getId()); System.out.println("#activities after find: " + found.getActivities().size()); System.out.println("#appointments after find: " + found.getAppointments().size()); } private static Event save(Event entity) { entityManager.getTransaction().begin(); Event result = entityManager.merge(entity); entityManager.getTransaction().commit(); return result; } private static Event find(long id) { entityManager.getTransaction().begin(); Event result = entityManager.find(Event.class, id); entityManager.getTransaction().commit(); return result; } static OpenJPAEntityManager entityManager = (OpenJPAEntityManager) Persistence.createEntityManagerFactory( "openjpa_test", System.getProperties()).createEntityManager(); I've attached all the files a zip. > multiple @OneToMany relations with entities with common super type using InheritanceType.JOINED are incorrectly fetched > ----------------------------------------------------------------------------------------------------------------------- > > Key: OPENJPA-1718 > URL: https://issues.apache.org/jira/browse/OPENJPA-1718 > Project: OpenJPA > Issue Type: Bug > Affects Versions: 2.0.0 > Reporter: Peter Rademaker > > I have an entity "Event" which has two @OneToMany relations with two entities "Appointment" and "Activity" which both have the same superclass "Booking". > After saving an Event with 1 Activity and 1 Appointment and retrieving it using find, the Event is returned with 2 (!) Activities and 1 Appointment. One of these Activities seems > to contain the data of the Appointment. > I noticed that two things both seem to make it work as excepted: > (1) change the @Inheritance strategy to one of InheritanceType.SINGLE_TABLE or InheritanceType.TABLE_PER_CLASS > (2) remove the @Version field from "Event" > These are the entity configurations: > @Entity > public final class Event { > @Id > @GeneratedValue > protected Long id; > @Version > protected Integer version; > @OneToMany(cascade = ALL, mappedBy = "event", fetch = FetchType.EAGER) > private List activities = new ArrayList(); > @OneToMany(cascade = ALL, mappedBy = "event", fetch = FetchType.EAGER) > private List appointments = new ArrayList(); > ... > } > @Entity > @Inheritance(strategy = InheritanceType.JOINED) > public class Booking { > @Id > @GeneratedValue > protected Long id; > @ManyToOne(optional = true, cascade = ALL, fetch = FetchType.EAGER) > protected Event event; > > @Basic(fetch = FetchType.EAGER) > public String name; > ... > } > @Entity > public final class Activity extends Booking { > ... > } > @Entity > public final class Appointment extends Booking { > ... > } > This is the "test" which illustrates the problem: > public static void main(String[] args) { > Event event = new Event(); > > Appointment appointment = new Appointment("APPOINTMENT"); > appointment.setEvent(event); > event.addAppointment(appointment); > Activity activity = new Activity("ACTIVITY"); > activity.setEvent(event); > event.addActivity(activity); > > System.out.println("#activities before saving: " + event.getActivities().size()); > System.out.println("#appointments before saving: " + event.getAppointments().size()); > > Event saved = save(event); > System.out.println("#activities after saving: " + saved.getActivities().size()); > System.out.println("#appointments after saving: " + saved.getAppointments().size()); > > Event found = find(saved.getId()); > System.out.println("#activities after find: " + found.getActivities().size()); > System.out.println("#appointments after find: " + found.getAppointments().size()); > } > > private static Event save(Event entity) { > entityManager.getTransaction().begin(); > Event result = entityManager.merge(entity); > entityManager.getTransaction().commit(); > return result; > } > > private static Event find(long id) { > entityManager.getTransaction().begin(); > Event result = entityManager.find(Event.class, id); > entityManager.getTransaction().commit(); > return result; > } > > static OpenJPAEntityManager entityManager = (OpenJPAEntityManager) Persistence.createEntityManagerFactory( > "openjpa_test", System.getProperties()).createEntityManager(); > I've attached all the files in a zip. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.