-->
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.  [ 4 posts ] 
Author Message
 Post subject: Collection Mapping with index
PostPosted: Sun May 17, 2009 1:57 pm 
Newbie

Joined: Sun May 17, 2009 1:40 pm
Posts: 3
I have a ContactInformation class with a collection of ContactDetails. This has to be because a history of contact details needs to be maintained for each contact. Is it possible to map a property called latestContactDetails in ContactInformation class, since most of the querying is based on the latest information?


Top
 Profile  
 
 Post subject: Re: Collection Mapping with index
PostPosted: Tue May 19, 2009 11:46 am 
Regular
Regular

Joined: Wed Jun 20, 2007 1:53 am
Posts: 75
post your mapping files here.


Top
 Profile  
 
 Post subject: Re: Collection Mapping with index
PostPosted: Tue May 19, 2009 1:33 pm 
Newbie

Joined: Sun May 17, 2009 1:40 pm
Posts: 3
This is the contact class, it's one per person.. contact details change many times and history has to be maintained, hence we've used one to many mapping.

Code:
@Entity

@Table(name = "contact")

public class Contact implements Serializable {

   private Long id;

   private String createdBy;

   private boolean deleted;

   private Date creationDate;



   private ContactType contactType;

   private List<ContactDetails> contactDetails;



   @Id

   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CONTACT_SEQ")

   @SequenceGenerator(name = "CONTACT_SEQ", sequenceName = "CONTACT_SEQ")

   @Column(name = "contact_id")

   public Long getId() {

      return id;

   }



   public void setId(Long id) {

      this.id = id;

   }



   @Column(name = "created_by_emp")

   public String getCreatedBy() {

      return createdBy;

   }



   public void setCreatedBy(String createdBy) {

      this.createdBy = createdBy;

   }



   @Column(name = "is_deleted")

   public boolean isDeleted() {

      return deleted;

   }



   public void setDeleted(boolean deleted) {

      this.deleted = deleted;

   }



   @Column(name = "creation_date")

   public Date getCreationDate() {

      return creationDate;

   }



   public void setCreationDate(Date creationDate) {

      this.creationDate = creationDate;

   }



   @Column(name = "contact_type_id")

   @Enumerated(EnumType.STRING)

   public ContactType getContactType() {

      return contactType;

   }



   public void setContactType(ContactType contactType) {

      this.contactType = contactType;

   }



   @OneToMany(mappedBy = "contact", fetch = FetchType.LAZY)

   @OrderBy("modifiedDate desc")

   public List<ContactDetails> getContactDetails() {

      return contactDetails;

   }



   public void setContactDetails(List<ContactDetails> contactDetails) {

      this.contactDetails = contactDetails;

   }
}


This is the contact details entity, generated each time any property changes..
Code:
public class ContactDetails implements Serializable {

   private static final long serialVersionUID = -8983529588217749223L;



   private Long id;



   private String firstName;

   private String lastName;

   private String emailAddress;

   private String phoneNumber;

   private String mobilePhoneNumber;

   private String title;

   private String modifiedBy;


   @Id

   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CONTACT_DETAILS_SEQ")

   @SequenceGenerator(name = "CONTACT_DETAILS_SEQ", sequenceName = "CONTACT_DETAILS_SEQ")

   @Column(name = "contact_details_id")   

   public Long getId() {

      return id;

   }

   public void setId(Long id) {

      this.id = id;

   }

   @Column(name = "first_name")

   public String getFirstName() {

      return firstName;

   }

   public void setFirstName(String firstName) {

      this.firstName = firstName;

   }


   @Column(name = "last_name")

   public String getLastName() {

      return lastName;

   }

   

   public void setLastName(String lastName) {

      this.lastName = lastName;

   }



   @Column(name = "email_address")

   public String getEmailAddress() {

      return emailAddress;

   }

   public void setEmailAddress(String emailAddress) {

      this.emailAddress = emailAddress;

   }



   @Column(name = "phone_number")

   public String getPhoneNumber() {

      return phoneNumber;

   }

   public void setPhoneNumber(String phoneNumber) {

      this.phoneNumber = phoneNumber;

   }



   @Column(name = "mobile_phone_number")

   public String getMobilePhoneNumber() {

      return mobilePhoneNumber;

   }

   public void setMobilePhoneNumber(String mobilePhoneNumber) {

      this.mobilePhoneNumber = mobilePhoneNumber;

   }



   @Column(name = "title")

   public String getTitle() {

      return title;

   }

   public void setTitle(String title) {

      this.title = title;

   }



   @Column(name = "modified_by_emp")

   public String getModifiedBy() {

      return modifiedBy;

   }

   public void setModifiedBy(String modifiedBy) {

      this.modifiedBy = modifiedBy;

   }   
}



How would I map the latest details record to the contact class?


Top
 Profile  
 
 Post subject: Re: Collection Mapping with index
PostPosted: Tue May 19, 2009 2:12 pm 
Beginner
Beginner

Joined: Wed Nov 12, 2008 12:07 pm
Posts: 21
I think you could use the @IndexColumn to implement ordering in your list. Then you could use pagination or something like this to get only the last one when you need it.

But I think I would create a new association: ContactDetails latestContactDetails and only store the old ones in ContactDetails list.


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

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.