-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: OneToMany with compound key
PostPosted: Wed Dec 10, 2008 5:07 am 
Newbie

Joined: Wed Dec 10, 2008 4:42 am
Posts: 1
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.