-->
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: Nested Composite Primary/Foreign Keys
PostPosted: Wed Nov 12, 2008 4:49 am 
Newbie

Joined: Wed Nov 12, 2008 4:28 am
Posts: 1
Hi,

I have a strange problem because of a legacy database.

In database there are tables like that:

FirstTable
-------------
first_id (Pk)


SecondTable
----------------
second_id (PK)
first_id (PK/FK from FirstTable)


ThirdTable
-------------
third_id (PK)
second_id (PK/FK from SecondTable)
first_id (PK/FK from SecondTable)


FourthTable
--------------
fourth_id (PK)
third_id (FK from ThirdTable)
second_id(FK from ThirdTable)
first_id (FK from ThirdTable)


but i cannot write POJO classes with annotation. I try to use ManyToOne and JoinColumns annotation between "Fourt" and "Third". Then I write PK class for "Third" which include third_id and "Second" POJO object:

Code:
public class Fourt{

@ManyToOne
@JoinColumns({@JoinColumn(name="THIRD_ID", referencedColumnName = "THIRD_ID"),
              @JoinColumn(name="SECOND_ID", referencedColumnName = "SECOND_ID"),
              @JoinColumn(name="FIRST_ID", referencedColumnName = "FIRST_ID")
   })
   private Third third;

}


public class Third{

@EmbeddedId
private ThirdPk thirdPk;
...
}


public class ThirdPk{

@Column(name="Third_id")
private Long thirdId;

@ManyToOne
   @JoinColumns({@JoinColumn(name="second_id", referencedColumnName = "second_id"),
        @JoinColumn(name="first_id", referencedColumnName = "first_id")
})
private Second second;
}




is there another way to model this senario?


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.