Hibernate version: 3.3.0.GA
I have the following generic class:
Code:
@Entity
@Table (name="tbl_event")
public class Event {
}
and
Code:
@Entity
public class A extends BaseEntity {
private List<Event> events = null;
@OneToMany
@JoinColumns(
{@JoinColumn (name="entityId"), @JoinColumn (name="entityName")}
)
public List<Event> getEvents() {
...
}
// more code
}
I also have a class B, extending the same
BaseEntity, and which I want to have the same
events list.
Class
BaseEntity is a
MappedSupperClass that handles primary keys of all my entities.
The issue is, that I would like to have the tbl_event tabel to contain all events for all entities, not just events for a certain type. So the table should look something like
Code:
id entity_id entity_name more_columns
0 3 A ...
1 3 A ...
2 4 B ...
Without anything else in the
Event class to map back to the
A class, I get the following error:
A Foreign key refering package.A from package.Event has the wrong number of column. should be 1.
I was thinking about adding the following the the
Event class:
Code:
private BaseEntity entityRelation;
@ManyToOne
@JoinColumns({@JoinColumn(name = "entityId"), @JoinColumn(name = "entityName")})
public BaseEntity getEntityRelation() {
...
}
But this cannot be done, because BaseEntity is not an entity in itself. Adding a mapping to A in the Event class is not an option, as that is not a generic solution for the Event class.
Question is: do I miss something here, or can this construct simply not been implemented the way I want it?