persistence@glassfish.java.net

JPA SingleTable inheritance with _at_OneToMany problem

From: tiemykim <tiemykim_at_hotmail.com>
Date: Thu, 3 Sep 2009 14:25:32 -0700 (PDT)

I have a parent class with three subclasses inheriting from it using Single
Table inheritance. I then have another class which has a parent class object
with a @OneToMany - @ManyToOne relationship. I get an error when trying to
create the database tables and was wondering if anyone had any insight into
why, perhaps I am missing or am using the incorrect annotations. Thanks for
your time.

Below is the error:

"Multiple possible other sides to relationship
from: AnotherClass/parentClasses
1. SubclassA/otherClass
2. SubclassB/otherClass
Looking for type: SubclassB
Add @OneToMany(targetEntity=xx.class) to fix as I don't parse the collection
type."

Below is my code, the contents of many of the classes have been omitted.

Entity(name="ParentClass ")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="type",
discriminatorType=DiscriminatorType.STRING)
public abstract class ParentClass {
@ManyToOne()
OtherClass other;

private String type;
}

Entity(name="SubclassA")
@DiscriminatorValue("A")
public class SubclassA extends ParentClass {}

Entity(name="SubclassB")
@DiscriminatorValue("B")
public class SubclassB extends ParentClass {}

Entity(name="SubclassC")
@DiscriminatorValue("C")
public class SubclassC extends ParentClass {}

@Entity(name="OtherClass")
public class OtherClass {

@OneToMany(mappedBy="OtherClass
",targetEntity=ParentClass.class,cascade=CascadeType.PERSIST)
private List< ParentClass > parentClasses = new ArrayList< ParentClass >();
}
-- 
View this message in context: http://www.nabble.com/JPA-SingleTable-inheritance-with-%40OneToMany-problem-tp25284380p25284380.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.