-->
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.  [ 3 posts ] 
Author Message
 Post subject: Selfreference Mapping
PostPosted: Thu Jun 10, 2010 11:40 am 
Newbie

Joined: Thu Jun 10, 2010 11:31 am
Posts: 2
Hi, I am new in hibernate so I have a problem to solve.
I have 2 tables:

KEYFRAME (id integer, frame varchar, video integer);
KEYFRAMEMATCHING (keyframe1 integer, keyframe2 integer, similarity integer);

These tables have 1:N associations...

So how can I map them in hibernate.hbm.xml?

I have read many examples on this but I didn't solve my problem.

Thank you,
Francesco.


Top
 Profile  
 
 Post subject: Re: Selfreference Mapping
PostPosted: Thu Jun 10, 2010 11:52 am 
Beginner
Beginner

Joined: Wed Jul 01, 2009 8:11 am
Posts: 34
i'm not sure if you have already understood the way Hibernate works. in Hibernate you don't map tables, in Hibernate you map classes. this means you will need two class for the two tables of yours:

Code:
class KEYFRAME {
   private Long id; <- use a Long as id, best solution, it has more size than the Integer
   private String frame;
   private Long video;

  // getter and setter for the properties
}
class KEYFRAMEMATCHING {
    private Long id;
    private KEYFRAME keyframe1;
    private KEYFRAME keyframe2;
    private Integer similarity;

  // getter and setter for the properties
}


the next step is you need mapping files for the classes... this is not difficult. best option is to buy a book and learn from it. i'm using "Hibernate in Action". things are nicely explained there. you should really try and learn how to do it by yourself.


Top
 Profile  
 
 Post subject: Re: Selfreference Mapping
PostPosted: Thu Jun 10, 2010 12:22 pm 
Newbie

Joined: Thu Jun 10, 2010 11:31 am
Posts: 2
garz wrote:
i'm not sure if you have already understood the way Hibernate works. in Hibernate you don't map tables, in Hibernate you map classes. this means you will need two class for the two tables of yours:

Code:
class KEYFRAME {
   private Long id; <- use a Long as id, best solution, it has more size than the Integer
   private String frame;
   private Long video;

  // getter and setter for the properties
}
class KEYFRAMEMATCHING {
    private Long id;
    private KEYFRAME keyframe1;
    private KEYFRAME keyframe2;
    private Integer similarity;

  // getter and setter for the properties
}


the next step is you need mapping files for the classes... this is not difficult. best option is to buy a book and learn from it. i'm using "Hibernate in Action". things are nicely explained there. you should really try and learn how to do it by yourself.


thanks for your reply.
KeyFrameMatching have two primary keys -> keyframe1 and keyframe2. These attributes are even foreign key of KeyFrame table.
Now I must mapping these two classes (not in annotation mode) but I don't know how.
In "hibernate in action" my "case" similar to figure 3.11 at page 109 -> ITEM and BID but instead of having one PK and one FK, I have two PK that are the same of FK (for example BID_ID and ITEM_ID are two PK and FK of BID tables that refer themselves to ITEM_ID of ITEM table).

So I don't know how can I solve and how map must I do (mapping files for the class)...
Code:
public class KeyFrame extends DomainObject {
   private static final long serialVersionUID = 1L;
   private String frame;
   private Video video = new Video();
   private Set<KeyFrame> keyframes = new HashSet<KeyFrame>();
        ...

Code:
public class KeyFrameMatching extends DomainObject {
   private static final long serialVersionUID = 1L;
   private int similarity;
   private KeyFrame keyframe1;
   private KeyFrame keyframe2;
        ...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.