-->
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.  [ 13 posts ] 
Author Message
 Post subject: Composite id with manyToOne references (from a legacy db)
PostPosted: Mon Nov 13, 2006 10:51 am 
Regular
Regular

Joined: Thu Oct 13, 2005 4:19 am
Posts: 98
I've tried and errored all the propositions in the hibernate and hibernate-annotations manual, but I can't get this to work.
(Might I humble point out that http://www.hibernate.org/hib_docs/annot ... identifier could use more examples on mapping composite keys?)



OrderLine has a composite key of OrderLine and Product.

Code:
@Entity
???
public class OrderLine {
    ...

    ???
    @ManyToOne()
    @NotNull
    @JoinColumn(name = "order", nullable = false)
    public Order getOrder() {...}

    ???
    @ManyToOne()
    @NotNull
    @JoinColumn(name = "product", nullable = false)
    public Product getProduct() {...}

    ...
}


What do I place at the ???
I 've also made a OrderLineId class to use @IdClass, but that didn't work either.

All the examples I 've found don't use associations as part of their composite keys. I hope that isn't illegal?

_________________
http://www.ohloh.net/accounts/ge0ffrey


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 13, 2006 6:54 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I'm afraid I never tested your case. It should technically work.
Open a JIRA issue with a running test case. But this is probably not my priority so a complete patch might be your way out :-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 4:48 am 
Regular
Regular

Joined: Thu Oct 13, 2005 4:19 am
Posts: 98
What replacements of ??? should technically work?

I've tried a great number of combinations (some logical, some ridiculous) of @Id, @IdClass, @Embeddable, @EmbeddableId with @ManyToOne, @JoinColumn.

_________________
http://www.ohloh.net/accounts/ge0ffrey


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 10:28 am 
Regular
Regular

Joined: Thu Oct 13, 2005 4:19 am
Posts: 98
It took me a good while to get it all setup, but here's a testcase patch :)

http://opensource.atlassian.com/project ... se/ANN-492

The error is the same as my app gets in legal configs using IdClass: "repeated column"

_________________
http://www.ohloh.net/accounts/ge0ffrey


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 11:35 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
When I mean technically, I mean it should work or this is a bug

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 14, 2006 12:46 pm 
Newbie

Joined: Thu Dec 02, 2004 2:13 pm
Posts: 10
I'm experiencing the same problem, is there any resolution to this?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 6:35 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Go and watch (the function) the JIRA issue
http://opensource.atlassian.com/project ... se/ANN-492

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Composite keys with Associations
PostPosted: Sat Jan 06, 2007 1:08 pm 
Newbie

Joined: Fri Aug 06, 2004 5:16 pm
Posts: 7
I had the same problem, and finally realized it was a bug in Hibernate's implementation of JPA. So after trying every single combination over a couple of days like Geoffrey did, I finally just switched to Toplink's implementation, and got past the problem in 15 minutes.

It's a shame this is not a higher priority bug since pretty much any legacy database is going to utilize composite natural keys with associations on parts of the key. The inability to model this makes Hibernate's implementation basically unusable for legacy databases.


Top
 Profile  
 
 Post subject: Re: Composite keys with Associations
PostPosted: Mon Jan 08, 2007 1:25 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
sguillory wrote:
The inability to model this makes Hibernate's implementation basically unusable for legacy databases.


Hibernate is the most flexible JPA implementation regarding legacy and exotic mappings. Do not let a single bug hidding the global feature set.

@IdClass is barely used contrary to @EmbeddedId when dealing with composite it.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Composite keys with Associations
PostPosted: Mon Jan 08, 2007 2:06 pm 
Newbie

Joined: Fri Aug 06, 2004 5:16 pm
Posts: 7
Hibernate's implementation of JPA may be the most flexible for legacy and exotic mappings, however, currently it is incapable of modeling composite keys with associations on parts of the key. It doesn't matter if you use the @IdClass annotation style or the @EmbeddedId annotation style.

So I currently can't use hibernate's implementation. However, I am watching this issue and will try it again when it is fixed. I am just a bit dissappointed to hear that this bug is not a high priority since it renders Hibernate Annotations useless for legacy databases.

Stan


Top
 Profile  
 
 Post subject: Re: Composite keys with Associations
PostPosted: Wed Jan 10, 2007 10:04 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
sguillory wrote:
however, currently it is incapable of modeling composite keys with associations on parts of the key. It doesn't matter if you use the @IdClass annotation style or the @EmbeddedId annotation style.


You are wrong. There is a pretty comprehensive support released already http://fisheye.labs.jboss.com/browse/Hibernate/branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone

A patch was probided, and marked to be fixed for 3.2.2 (ie the next version), I can't see how it is not a high priority.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Composite keys with Associations
PostPosted: Wed Jan 10, 2007 11:47 am 
Newbie

Joined: Fri Aug 06, 2004 5:16 pm
Posts: 7
I guess there is some confusion on my part. There appear to be two bugs opened on this issue: 492, and 499. 492 is still marked open while 499 is marked closed.

As for my assumption that the bug was not a high priority, I refer to your quote from November 13, 2006:

"But this is probably not my priority so a complete patch might be your way out :-)"

I think even you will admit that your english isn't the best, so I took this to mean ". . . not *high* priority . . .", since the sentence didn't make any sense as written.

At any rate, I'm glad to hear the issue has been resolved. I probably will stick with TopLink for now sense it seems to be a more robust implementation at this point, but I will definitely review the 3.2.2 release when it becomes available.

Thanks,
Stan


Top
 Profile  
 
 Post subject: Re: Composite keys with Associations
PostPosted: Wed Jan 10, 2007 11:50 am 
Newbie

Joined: Fri Aug 06, 2004 5:16 pm
Posts: 7
I guess there is some confusion on my part. There appear to be two bugs opened on this issue: 492, and 499. 492 is still marked open while 499 is marked closed.

As for my assumption that the bug was not a high priority, I refer to your quote from November 13, 2006:

"But this is probably not my priority so a complete patch might be your way out :-)"

I think even you will admit that your english isn't the best, so I took this to mean ". . . not *high* priority . . .", since the sentence didn't make any sense as written.

At any rate, I'm glad to hear the issue has been resolved. I probably will stick with TopLink for now sense it seems to be a more robust implementation at this point, but I will definitely review the 3.2.2 release when it becomes available.

Thanks,
Stan


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