On 08/08/11 03:14, Robert Klemme wrote:
On 07.08.2011 18:45, Frank Langelage wrote:
On 07.08.11 13:38, Lionel wrote:
This may be a little off topic but I'm sure there are some experts in
here.
I'm having some troubles getting using a foreign key as a primary key.
In this post I will use the most simple issue I'm having trouble with.
Here's some snippets (pharmacy project):
public abstract class AbstractDrugModel
{
private String name;
private IntravascularDrug ivDrug;
}
public class IntravascularDrug
{
private AbstractDrugModel drug;
}
I can't help you with your problem but want to give a comment to this
mail.
Your class design does not make sense to me. You have a circular
reference between these two classes. Java allows this, but this is bad
design in my eyes.
... but very common for bidirectional relationships. If instances of
both classes need to be able to navigate the relationship that design is
the most efficient solution.
Yes. This is normal design. But read one.
And this might be the cause that hibernate cannot work with this design.
Yes, might be.
My original relationship was actually unidirectional, there was no need
for the IntravascularDrug to know about the AbstractDrugModel. However,
to map the relationship in Hibernate somehow Hibernate needs to be able
to get the primary key for IntravascularDrug which happens to be the
primary key of AbstractDrugModel and is hence also a foreign key of
IntravascularDrug.
I thought there might be more knowledge of hibernate [sic] on this forum, but
based on the responses it seems it is too specific for this forum. I
just wasn't getting responses to other questions on the Hibernate forum
(and neither were many other people though there are a high number of
posts) so I decided to try on my preferred medium :).
The annotative version (JPA-compliant) would be easier to follow.