-->
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: ManyToMany relation with a MappedSuperclass
PostPosted: Tue Mar 20, 2007 7:29 pm 
Newbie

Joined: Tue Mar 20, 2007 6:53 pm
Posts: 1
Ok, i've been searching and experimenting on how to do this, and i have found zero examples or documentation on this subject... Here is the problem:


I have an abstract class like this (simplified):

Code:
@MappedSuperclass
public abstract class Person implements Serializable {
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private long id;

  @Basic
  private String name;

  @Basic
  private String telephone;

  //more properties, like: address, email, etc...
}


Then i have 3 childs, that looks like this:

Code:
@Entity
@Table(name="TBL_USERS")
public class User extends Person implements Serializable {
  @Basic
  private String username;

  @Basic
  private String password;

  //more user-specific fields
}


Code:
@Entity
@Table(name="TBL_CONTACTS")
public class Contact extends Person implements Serializable {
  @Basic
  private String company;

  //more contact-specific fields
}


Code:
@Entity
@Table(name="TBL_CLIENTS")
public class Client extends Person implements Serializable {
  @ManyToOne
  @JoinColumn(name="asesor_fk")
  private User asesor;

  //more client-specific fields
}


Ok, everything here is perfect, the Application works fine, with no problems at all.

Ok, the problem is that i want to have something like this:

Code:
@Entity
@Table(name="TBL_MEETINGS")
public class Meeting implements Serializable {
  //meeting-specific fields..., like id, date, time, place, etc...

  @ManyToMany
  @JoinTable(name = "TBL_MEETING_GUESTS",
   joinColumns = @JoinColumn(name = "meeting_fk"),
   inverseJoinColumns = @JoinColumn(name = "person_fk"))
  private List<Person> guests;            //THIS IS THE PROBLEM!!
}


The problem is that i don't know how to specify a database column wich would contain a discriminator value inside TBL_MEETING_GUESTS, this way, Hibernate could read this column, and load the record from the corresponding table. For example, to have something like this:

Code:
@ManyToMany
@JoinTable(name = "TBL_MEETING_GUESTS",
      joinColumns = @JoinColumn(name = "meeting_fk"),
      inverseDiscriminatorColumn = @DiscriminatorColumn(name = "person_type", discriminatorType = DiscriminatorType.STRING),
      inverseJoinColumns = @JoinColumn(name = "person_fk"))
private List<Person> guests;


And then add a discriminator value to the classes: User, Contact and Client. This discriminator value should be used only on the Meeting class.


Well, this is what i want to do. Reading around the web, i saw something about writing a custom EntityPersister. Maybe this can be the solution, but i only need the custom persister on the Meeting class.


I want to know if this is the way to go, or if there is an easier way to implement this.

Thanks :)

_________________
------------
Hilario Perez Corona
"No Religion Higher Than Truth"


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.