openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter Rademaker (JIRA)" <>
Subject [jira] Created: (OPENJPA-1718) multiple @OneToMany relations with entities with common super type using InheritanceType.JOINED are incorrectly fetched
Date Wed, 07 Jul 2010 15:01:50 GMT
multiple @OneToMany relations with entities with common super type using InheritanceType.JOINED
are incorrectly fetched

                 Key: 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:  

public final class Event  {
	protected Long id;
	protected Integer version;

	@OneToMany(cascade = ALL, mappedBy = "event", fetch = FetchType.EAGER)
	private List<Activity> activities = new ArrayList<Activity>();

	@OneToMany(cascade = ALL, mappedBy = "event", fetch = FetchType.EAGER)
	private List<Appointment> appointments = new ArrayList<Appointment>();

@Inheritance(strategy = InheritanceType.JOINED)
public class Booking {
	protected Long id;

	@ManyToOne(optional = true, cascade = ALL, fetch = FetchType.EAGER)
	protected Event event;
	@Basic(fetch = FetchType.EAGER)
	public String name;

public final class Activity extends Booking {

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");
		Activity activity = new Activity("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) {
		Event result = entityManager.merge(entity);
		return result;
	private static Event find(long id) {
		Event result = entityManager.find(Event.class, id);
		return result;
	static OpenJPAEntityManager entityManager = (OpenJPAEntityManager) Persistence.createEntityManagerFactory(
			"openjpa_test", System.getProperties()).createEntityManager();

I've attached all the files a zip.

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

View raw message