-->
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: Mapping Problematic
PostPosted: Tue Oct 28, 2008 7:05 am 
Beginner
Beginner

Joined: Wed May 25, 2005 8:25 am
Posts: 30
Hello everybody.

(my apologize if my english isn't always good :) )

I have a mapping problem. I start a new project and I have to connect to an existing database (under oracle).

Here is the concerned tables :

- Contact : information about a person
- Mail : list of contact's mail
- mailtype : type of mail (personal, prof ...)

An association table map these 3 tables.

The Primary key is the agregation of 3 id's :

contact + mail + type of mail.

an entry looks in the association table looks like that :

id_contact id_mail type_mail
0000001 0000001 P

Here is my current mapping :

Contact :


Code:
@Entity
@Table(schema = "COMMON", name = "COM_CONTACT")
@NamedQueries(
   {
      @NamedQuery(name="Contact.findById", query="select c from Contact c where c.id = :id")
   }
)
public class Contact {

   @Id
   //@GeneratedValue(generator="triggerAssigned")
   //@GenericGenerator(name="triggerAssigned",
   //        strategy = "com.edhec.usrmgt.orm.hibernate.util.TriggerAssignedIdentityGenerator"
   //      )
   //@Column(name = "ID",length = 20, unique=false, nullable=false)
   protected String id;
   
   @Column(name = "NAME",length = 250, unique=false, nullable=false)
   protected String name;
   
   @Column(name = "INTERNAL_REFERENCE",length = 50, unique=false, nullable=true)
   protected String internalReference;
   
   @Column(name = "LOGIN",length = 250, unique=true, nullable=true)
   protected String login;
   
   @Column(name = "PASSWORD",length = 250, unique=false, nullable=true)
   protected String password;
   
   @Column(name = "WEB_CODE",length = 250, unique=true, nullable=true)
   protected String webCode;
   
   @Column(name = "DATE_CREATED", length = 30, unique=false, nullable=true)
   protected String dateCreated;
   
   @Column(name = "DATE_MODIFIED", length = 30, unique=false, nullable=true)
   protected String dateModified;
   
   @ManyToMany(
         fetch=FetchType.EAGER,
           targetEntity=ComMail.class,
           cascade={CascadeType.PERSIST, CascadeType.MERGE}
       )
       @JoinTable(
           name="COM_CONTACT_MAIL",
           joinColumns=@JoinColumn(name="CNT_ID"),
           inverseJoinColumns=@JoinColumn(name="MAL_ID")
       )
   protected Collection<ComMail> mail;
   
   public Contact() {
      
   }

   public String getId() {
      return id;
   }

   public void setId(String id) {
      this.id = id;
   }

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public String getInternalReference() {
      return internalReference;
   }

   public void setInternalReference(String internalReference) {
      this.internalReference = internalReference;
   }

   public String getLogin() {
      return login;
   }

   public void setLogin(String login) {
      this.login = login;
   }

   public String getPassword() {
      return password;
   }

   public void setPassword(String password) {
      this.password = password;
   }

   public String getWebCode() {
      return webCode;
   }

   public void setWebCode(String webCode) {
      this.webCode = webCode;
   }

   public String getDateCreated() {
      return dateCreated;
   }

   public void setDateCreated(String dateCreated) {
      this.dateCreated = dateCreated;
   }

   public String getDateModified() {
      return dateModified;
   }

   public void setDateModified(String dateModified) {
      this.dateModified = dateModified;
   }

   
   
   public Collection<ComMail> getMail() {
      return mail;
   }

   public void setMail(Collection<ComMail> mail) {
      this.mail = mail;
   }
   
}


Mail :

Code:
@Entity
@Table(schema = "COMMON", name = "COM_MAIL")
@NamedQuery(name="ComMail.findById", query="select c from ComMail c where c.id = :id")
public class ComMail {

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   protected String id;
   
   @Column(name = "MAIL",length = 250, unique=true, nullable=true)
   protected String mail;
   
   @Column(name = "URL",length = 250, unique=false, nullable=true)
   protected String url;
   
   @Column(name = "DATE_CREATED",length = 250, unique=true, nullable=true)
   protected String dateCreated;
   
   @Column(name = "DATE_MODIFIED",length = 250, unique=true, nullable=true)
   protected String dateModified;

   @ManyToMany(mappedBy = "mail")
   @JoinColumn(name="MAL_ID")
   protected Collection<Contact> contact;
   
   @OneToOne(
      fetch=FetchType.EAGER,
        targetEntity=ComAdressKind.class,
        cascade={CascadeType.PERSIST, CascadeType.MERGE}
    )
    @JoinTable(
        name="COM_CONTACT_MAIL",
        joinColumns=@JoinColumn(name="MAL_ID"),
        inverseJoinColumns=@JoinColumn(name="AKD_ID")
    )
   protected ComAdressKind adressKind;
   
   public String getId() {
      return id;
   }

   public void setId(String id) {
      this.id = id;
   }

   public String getMail() {
      return mail;
   }

   public void setMail(String mail) {
      this.mail = mail;
   }

   public String getUrl() {
      return url;
   }

   public void setUrl(String url) {
      this.url = url;
   }

   public String getDateCreated() {
      return dateCreated;
   }

   public void setDateCreated(String dateCreated) {
      this.dateCreated = dateCreated;
   }

   public String getDateModified() {
      return dateModified;
   }

   public void setDateModified(String dateModified) {
      this.dateModified = dateModified;
   }

   @ManyToMany(mappedBy = "mail")
   @JoinColumn(name="MAL_ID")
   public Collection<Contact> getContact() {
      return contact;
   }

   public void setContact(Collection<Contact> contact) {
      this.contact = contact;
   }

   public ComAdressKind getAdressKind() {
      return adressKind;
   }

   public void setAdressKind(ComAdressKind adressKind) {
      this.adressKind = adressKind;
   }
}


mail type:

Code:
@Entity
@Table(schema = "COMMON", name = "COM_ADRESS_KIND")
@NamedQuery(name="ComAdressKind.findById", query="select c from ComAdressKind c where c.id = :id")
public class ComAdressKind {
   
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   protected String id;
   
   @Column(name = "DATE_CREATED",length = 30, unique=false, nullable=true)
   protected String dateCreated;
   
   @Column(name = "DATE_MODIFIED",length = 30, unique=false, nullable=true)
   protected String dateModified;

   @OneToOne(mappedBy = "adressKind")
   protected ComMail mail;
   
   public String getId() {
      return id;
   }

   public void setId(String id) {
      this.id = id;
   }

   public String getDateCreated() {
      return dateCreated;
   }

   public void setDateCreated(String dateCreated) {
      this.dateCreated = dateCreated;
   }

   public String getDateModified() {
      return dateModified;
   }

   public void setDateModified(String dateModified) {
      this.dateModified = dateModified;
   }

   public ComMail getMail() {
      return mail;
   }

   public void setMail(ComMail mail) {
      this.mail = mail;
   }
}


A contact can have one or more mail. A mail as a type.

For the moment I get in my contact the mail, but the mapping with type don't seem correct (I get nothing).

If someone have an idea ?

Thanks.

Jeremy


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.