0

Sorry if this is trivial question, or if I have misunderstood something and the concept is wrong.

I have fallowing tables:

External_Users_Details: +------------------+--------+------------+ | External_User_Id | Key | Value | +------------------+--------+------------+ | 1 | f_name | firstname | | 1 | l_name | lastneme | | 2 | f_name | firstname2 | | 2 | l_name | lastneme2 | +------------------+--------+------------+

Response_Details ╔════════════╦═════════════╦══════════════╦══════════════════╗ ║ Meeting_Id ║ Attendee_Id ║ Response_Seq ║ Response_Messege ║ ╠════════════╬═════════════╬══════════════╬══════════════════╣ ║ 123 ║ 1 ║ 1 ║ I will be there ║ ║ 123 ║ 1 ║ 2 ║ Changed my mind ║ ║ 123 ║ 2 ║ 1 ║ Yep. ║ ║ 123 ║ 123456 ║ 1 ║ I will be there. ║ ╚════════════╩═════════════╩══════════════╩══════════════════╝

Now, external users are stored in a table with key-value pairs, with complex @Id {External_User_Id , [Key]}.

When user invites external attendee to a meeting, he needs to fill out a form (type first name, last name, company name, some contact details) and at the same time he 'confirms' participation of external attendee.

Now, I would like to persist entity Response_Details, but in order to get Attendee_Id, I need to somehow create this user in External_Users_Details table.

Response_Details Entity mapping for this external attendee looks like this:

@Entity
@IdClass(CResponsePK.class)
@Table(name = "Response_Details")
public class CalendarResponse implements Serializable {
  @Id
  @Column(name = "Meeting_Id")
  private Integer meetingId;
  @Id
  @Column(name = "Attendee_Id")
  private Integer attendeeId;
  @Id
  @Column(name = "Response_Seq")
  private Integer responseSeq;
  @Transient //this is transient because I was getting exception that ID has to be the same like in  CResponsePK
  private Map<String, String> externalAttendee;
  //...
}

In addition I have a session customizer:

ClassDescriptor cd = session.getClassDescriptor(CalendarResponse.class);
DirectMapMapping dmm = new DirectMapMapping();
dmm.dontUseIndirection();
dmm.setReferenceTableName("External_Users_Details");
dmm.setDirectKeyFieldName("External_Users_Details.[key]");
dmm.setDirectFieldName("External_Users_Details.[value]");
dmm.setAttributeName("externalAttendee");
dmm.addReferenceKeyFieldName("AttendeeID", "External_User_Id");

cd.addMapping(dmm);

And the main questions:

  • How do I create External_Users_Details when I want to add response for external user?
  • Should I create External_Users_Details entity? (if so, how to add thos key-value pairs mapping in this entity)
  • Should it create automatically when I persist CalendarResponse entity?
  • Did I messed up the mappings beteen CalendarResponse and External_Users_Details? (if so, how should I do this?)
Kamila
  • 371
  • 5
  • 13
  • Try this http://stackoverflow.com/questions/25439813/difference-between-mapkey-mapkeycolumn-and-mapkeyjoincolumn-in-hibernate – Bilal BBB Jul 12 '16 at 14:15
  • Quote from the link above: "When you use a Map you always need to associate at least two entities"- does it mean I cannot map External_Users_Details to an entity itself? – Kamila Jul 13 '16 at 06:29

0 Answers0