Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Table per class inheritance problem

Migrating my application from hibernate I get an error.
It is a bug or an expected behavior?
In the end of the message you'll find the stack trace.

Here is the scenario:

I use a table per class inheritance hierarchy, and the ID is contained in
the abstract class, that is the father to all my entities.

consider I have something like:


#####################
## First class
#####################
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class SchoolStuff {
	
	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE)
	@Column(name = "ID")
	protected long id;

	public long getId() {
		return id;
	}

	private void setId(long id) {
		this.id = id;
	}
}


######################
## second class
######################
@Entity
public class ClassRoom extends SchoolStuff  {
	
	@OneToMany(mappedBy="classroom",
			cascade=CascadeType.ALL,
			fetch = FetchType.LAZY)
	private List<Student> studentList = new ArrayList<Student>();

	public List<Student> getStudentList() {
		return studentList;
	}

	public void setStudentList(List<Student> studentList) {
		this.studentList = studentList;
	}
	
	private String classRoomName;

	public void setClassRoomName(String classRoomName) {
		this.classRoomName = classRoomName;
	}

	public String getClassRoomName() {
		return classRoomName;
	}
}

#######################
## third class
#######################
@Entity
public class Student extends SchoolStuff {
	
	@ManyToOne(fetch= FetchType.LAZY)
	@JoinColumn(name="CLASS_ROOM_ID",referencedColumnName="ID"
		,nullable=false,updatable=true)
	private ClassRoom classroom = null;		
	
	public ClassRoom getClassroom() {
		return classroom;
	}

	public void setClassroom(ClassRoom classroom) {
		this.classroom = classroom;
	}

	private String name;

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {		
		return name;
	}
}


I get the stack trace: 

Local Exception Stack: 
Exception [EclipseLink-30005] (Eclipse Persistence Services -
2.1.0.v20100311-r6779):
org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for
persistence archives with ClassLoader:
sun.misc.Launcher$AppClassLoader@a39137
Internal Exception: javax.persistence.PersistenceException: Exception
[EclipseLink-28018] (Eclipse Persistence Services - 2.1.0.v20100311-r6779):
org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [SIRIUS_PU] failed.
Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence
Services - 2.1.0.v20100311-r6779):
org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class
com.marconi.fusion.db.jpa.impl.Student] has no primary key specified. It
should define either an @Id, @EmbeddedId or an @IdClass. If you have defined
PK using any of these annotations then make sure that you do not have mixed
access-type (both fields and properties annotated) in your entity class
hierarchy.
...
-- 
View this message in context: http://old.nabble.com/Table-per-class-inheritance-problem-tp28331304p28331304.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top