-->
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.  [ 2 posts ] 
Author Message
 Post subject: XDoclet and many-to-many relatioship
PostPosted: Fri Dec 22, 2006 2:35 pm 
Newbie

Joined: Fri Dec 22, 2006 2:32 pm
Posts: 16
Hello,

I have the following 3 database tables with a many-to-many relationship.
(Basically pictures in photoalbums). The database tables are at the
bottom.

I want to create Hibernate mappings in XDoclet with lazy-loading. I have
created Hibernate objects for each table, but I am unable to link these
using XDoclet 2 tags. I am attaching the field-identifiers below the
database tables. Do I have to use @hibernate.set, or can this be done with
the @hibernate.many-to-many somehow ?

Tables:

Code:
--Holds Pictures (primary key is BildeID)
CREATE TABLE `Bilde` (
  `BildeID` int(11) NOT NULL auto_increment,
  `BildeNavn` varchar(100) NOT NULL,
  `BildeBeskrivelse` text NOT NULL,
  `BildeMening` float NOT NULL,
  `BildeLastetOpp` timestamp NOT NULL default CURRENT_TIMESTAMP on update
CURRENT_TIMESTAMP,
  `BildeSistEndret` timestamp NOT NULL default '0000-00-00 00:00:00',
  `BildeFilnavn` varchar(100) NOT NULL,
  `BildeErPrivat` binary(1) NOT NULL,
  `BildeOrginalStorrelse` float NOT NULL,
  `BildeTotalStorrelse` float NOT NULL,
  `Brukernavn` varchar(50) NOT NULL,
  PRIMARY KEY  (`BildeID`)
)

--Holds Albums (Primary key is BildeAlbumID)
CREATE TABLE `BildeAlbum` (
  `BildeAlbumID` int(11) NOT NULL auto_increment,
  `BildeAlbumNavn` varchar(100) NOT NULL,
  `BildeAlbumBeskrivelse` text NOT NULL,
  `BildeAlbumOpprettet` timestamp NOT NULL default CURRENT_TIMESTAMP on
update CURRENT_TIMESTAMP,
  `BildeAlbumSistEndret` timestamp NOT NULL default '0000-00-00 00:00:00',
  `BildeAlbumErPrivat` binary(1) NOT NULL,
  `Brukernavn` varchar(50) NOT NULL,
  PRIMARY KEY  (`BildeAlbumID`)
)

-- Linking table links to BildeID and BildeAlbumID
CREATE TABLE `BildeAlbumBilde` (
  `BildeAlbumBildeID` int(11) NOT NULL auto_increment,
  `BildeAlbumBildeOpprettet` timestamp NOT NULL default CURRENT_TIMESTAMP
on update CURRENT_TIMESTAMP,
  `BildeAlbumID` int(11) NOT NULL,
  `BildeID` int(11) NOT NULL,
  PRIMARY KEY  (`BildeAlbumBildeID`)
)


Code:
Classes:
/**
* @hibernate.class table="Bilde"
*/
public class BildeData
{
   /**
    * @hibernate.id generator-class="increment" column="BildeID"
    * @return
    */
   private int bildeID;

   /**
    * @hibernate.property column="BildeNavn"
    */
   private String bildeNavn;

   /**
    * @hibernate.property column="BildeBeskrivelse"
    */
   private String bildeBeskrivelse;

   /**
    * @hibernate.property column="BildeLastetOpp"
    */
   private Date BildeLastetOpp;

   /**
    * @hibernate.property column="BildeSistEndret"
    */
   private Date BildeSistEndret;

   /**
    * @hibernate.property column="BildeFilnavn"
    */
   private String BildeFilnavn;

   /**
    * @hibernate.property column="BildeErPrivat"
    */
   private Boolean bildeErPrivat;

   /**
    * @hibernate.property column="BildeOrginalStorrelse"
    */
   private float BildeOrginalStorrelse;

   /**
    * @hibernate.property column="BildeTotalStorrelse"
    */
   private float BildeTotalStorrelse;

   /**
    * @hibernate.property column="Brukernavn"
    */
   private String Brukernavn;

/**
* @hibernate.class table="BildeAlbum"
*/
public class BildeAlbumData
{
   /**
    * @hibernate.id generator-class="increment" column="BildeAlbumID"
    */
   private int bildeAlbumID;

   /**
    * @hibernate.property column="BildeAlbumNavn"
    */
   private String bildeAlbumNavn;

   /**
    * @hibernate.property column="BildeAlbumBeskrivelse"
    */
   private String bildeAlbumBeskrivelse;

   /**
    * @hibernate.property column="BildeAlbumOpprettet"
    */
   private Date bildeAlbumOpprettet;

   /**
    * @hibernate.property column="BildeAlbumSistEndret"
    */
   private Date bildeAlbumSistEndret;

   /**
    * @hibernate.property column="BildeAlbumErPrivat"
    */
   private boolean bildeAlbumErPrivat;

   /**
    * @hibernate.property column="Brukernavn"
    */
   private String brukernavn;

/**
* @hibernate.class table="BildeAlbumBilde"
*/
public class BildeAlbumBildeData
{
   /**
    * @hibernate.id generator-class="increment" column="BildeAlbumBildeID"
    */
   private int bildeAlbumBildeID;

   /**
    * @hibernate.property column="BildeAlbumBildeOpprettet"
    */
   private Date bildeAlbumBildeOpprettet;

   /**
    * @hibernate.property column="BildeAlbumID"
    */
   private int bildeAlbumID;

   /**
    * @hibernate.property column="BildeID"
    */
   private int bildeID;

   /**
    * @hibernate.one-to-one
    */
   public BildeData bildeData;


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 25, 2006 8:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
XDoclet can be used to generate the HBMs for Many-to-many - examples and tests exist - also see XDoclet site for markup. Note: normally the link table is a compounded key representing each primary/foreign key field. You might be better off marking this up as a mapped first class entry and have two sets.


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