Best way for Entities [message #509079] |
Thu, 21 January 2010 10:59 |
sebastian.schneider Messages: 9 Registered: January 2010 |
Junior Member |
|
|
Hello,
I've got these three tables, which I'd like to use with Eclipselink.
Language (approx. 20 records)
=================
LANGUAGE_ID (PK)
Category: (approx. 10.000 records)
=================
CATEGORY_ID (PK)
CATEGORY_NUMBER
Category_Lang (approx. 20 x 10.000 = 200.000 records)
=================
CATEGORY_ID (FK)
LANGUAGE_ID (FK)
CATEGORY_NAME
CATEGORY_SHORTNAME
The classes:
@Entity
@Table(name = "LANGUAGE")
public class Language implements Serializable {
@Id
@Column(name = "LANGUAGE_ID")
private String id;
}
@Entity
@Table(name = "CATEGORY")
@SequenceGenerator(name = "CategorySequence", sequenceName = "SEQ_CATEGORY$CATEGORY_ID", allocationSize = 1)
public class Category implements Serializable {
@Id
@GeneratedValue(generator = "CategorySequence")
@Column(name = "CATEGORY_ID")
private int id;
@Column(name = "CATEGORY_NUMBER")
private boolean number;
@OneToMany(mappedBy = "category")
private List<CategoryLang> langs;
public List<CategoryLang> getLangs() {
return langs;
}
}
@Entity
@Table(name = "CATEGORY_LANG")
public class CategoryLang implements Serializable {
@Id
@ManyToOne(targetEntity = Category.class)
@JoinColumn(name = "CATEGORY_ID")
private Category category;
@Id
@Column(name = "LANGUAGE_ID")
private String languageId;
@Column(name = "CATEGORY_NAME")
private String name;
@Column(name = "CATEGORY_SHORTNAME")
private String shortName;
}
What is the best way migrate the following SQL query to EclipseLink
select c.categoryId, c.categoryNumber, cl.categoryName
from category c, category_lang cl
where c.categoryId = cl.categoryId
and cl.languageId = 'en'
order by cl.category_name
Thank you.
[Updated on: Thu, 21 January 2010 11:02] Report message to a moderator
|
|
|
|
Re: Best way for Entities [message #509124 is a reply to message #509111] |
Thu, 21 January 2010 13:07 |
sebastian.schneider Messages: 9 Registered: January 2010 |
Junior Member |
|
|
Hello,
thanks for your help.
The values aren't duplicated. Category_lang is the table which translates the name of the category in different languages.
I'm trying to explain the problem:
When I have let's say a class A with a Category category.
When I get a Object of A I want to have the category with the translated names of categoryNames for a given languageId.
Thanks
Basti
[Updated on: Thu, 21 January 2010 13:07] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03738 seconds