-->
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 association with Composite-id
PostPosted: Wed Feb 27, 2013 7:31 am 
Newbie

Joined: Wed Feb 27, 2013 7:11 am
Posts: 1
Hi, I'm new on Hibernate, I've a doubt about how can I represent this case:

-->Table Message:
- (PK) MsgSender -> Foreign key to table 'User'
- (PK) MsgDestination -> Foreign key to table 'User'
- (PK) MsgDateSend
- MsgContent
- IsReaded

-->Table User
-(PK) Username
- ...

This is my Message.hbm:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="Message" table="MESSAGE">
      <composite-id name="id" class="MessageId">
         <key-many-to-one name="MsgSender" class="User">
            <column name="msgSender"/>
         </key-many-to-one>
         <key-many-to-one name="MsgDestination" class="User">
            <column name="msgDestination"/>
         </key-many-to-one>
         <key-property name="msgDateSend" type="double" column="MsgDateSend"/>
      </composite-id>
      <property name="msgContent" type="java.lang.String">
         <column name="MsgContent" />
      </property>
      <property name="isReaded" type="boolean" access="field">
         <column name="ISREADED" />
      </property>
   </class>
</hibernate-mapping>


And this is my POJO's:
Class Message:
Code:
public class Message implements Serializable {
   /**
    *
    */
   private static final long serialVersionUID = -5319468638732762052L;
   private MessageId id;
   private String msgContent;
   private boolean isReaded;
   
   public Message() {
      this.id = new msgContentId();
   }
   
   /**
    * @return the id
    */
   public MessageId getId() {
      return id;
   }

   /**
    * @param id the id to set
    */
   public void setMessageId(MessageId mId) {
      this.id = mId;
   }

   /**
    * @return the msgContent
    */
   public String getMsgContent() {
      return msgContent;
   }

   /**
    * @param msgContent
    *            the msgContent to set
    */
   public void setMsgContent(String msgContent) {
      this.msgContent = msgContent;
   }

   /**
    * @return the isReaded
    */
   public boolean getIsReaded() {
      return isReaded;
   }

   /**
    * @param isReaded
    *            the isReaded to set
    */
   public void setIsReaded(boolean isReaded) {
      this.isReaded = isReaded;
   }
}


Class MessageId:
Code:
public class MessageId implements Serializable{
   /**
    *
    */
   private static final long serialVersionUID = 1L;
   User msgSender;
   User msgDestination;
   double msgSend;
   

   /**
    * @return the msgSender
    */
   public User getMsgSender() {
      return msgSender;
   }

   /**
    * @param msgSender
    *            the msgSender to set
    */
   public void setMsgSender(User msgSender) {
      this.msgSender = msgSender;
   }

   /**
    * @return the msgDestination
    */
   public User getMsgDestination() {
      return msgDestination;
   }

   /**
    * @param msgDestination
    *            the msgDestination to set
    */
   public void setMsgDestination(User msgDestination) {
      this.msgDestination = msgDestination;
   }

   /**
    * @return the msgSend
    */
   public double getMsgSend() {
      return msgSend;
   }

   /**
    * @param msgSend
    *            the msgSend to set
    */
   public void setMsgSend(double msgSend) {
      this.msgSend = msgSend;
   }
}


With this structure Hibernate makes no insert, delete, ...
Does anyone could help me solve this problem?

Thanks in advance.


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.