-->
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: CompositeId or something..
PostPosted: Mon Oct 30, 2006 8:01 am 
Newbie

Joined: Mon Oct 30, 2006 4:04 am
Posts: 1
I'm new to Hibernate and Annotations. I'm reading the Java Persistance with Hibernate, a great introduction, but I still can't 'solve' my problem..

I have two tables:
Code:
item(id, name, description_id)
description(id, language, description)

Now I would like to get an item record with the description in the correct language. In SQL it would be like:
Code:
SELECT i.name, d.description FROM item i LEFT OUTER JOIN description d ON i.description_id=d.id WHERE i.id=? AND d.language=?

So I've created two classes:
Code:
@Entity
public class Item() {
  @Id
  @GeneratedValue
  private Long id;
  private String name;
  @JoinColumn(name = "description_id")
  private Description description;
  ..
}
@Entity
public class Description() {
  @Id
  @GeneratedValue
  private Long id;
  private String language;
  private String description;
  ..
}

In my HQL query I can't specify the join and the column d.id is not available. I'm reading chapter 8 now... but maybe someone can help me.
First thing that's not correct is the Description class, the "id" is not unique, the combination of "id" and "language" is unique, so I should use a CompositeId?? Is it possible with annotations or should I change my strategy?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 6:25 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://blog.hibernate.org/cgi-bin/blosxom.cgi/2004/06/23#i18n
The filters might be useful too

_________________
Emmanuel


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.