I need to know how I can get one complete query in hibernate (
3.5.6) to get one list with games with full data with category and other game data translations.
Now, I have in Game two interfaces properties but Hibernate not permit mapped them, is normal, because interfaces are not persistent entities and Hibernate cant know it.
Some solution?. Thanks!
I have this BD structure:
My Hibernate Setup:
InterfacesCode:
public interface GameInt {
int getGame_id();
void setGame_id(int game_id);
String getTitle();
void setTitle(String title);
String getDescription();
void setDescription(String description);
}
public interface CategoryInt{
int getCategory_id();
void setCategory_id(int category_id);
String getName();
void setName(String name);
String getDescription();
void setDescription(String description);
void setCategory(Category category);
Category getCategory();
}
Persistent abstract superclassesCode:
@MappedSuperclass
public class GameLang implements GameInt {
private int game_id;
private String title;
private String description;
@Override
@Id
public int getGame_id() {
return game_id;
}
@Override
public void setGame_id(int game_id) {
this.game_id = game_id;
}
@Override
public String getTitle() {
return title;
}
@Override
public void setTitle(String title) {
this.title = title;
}
@Override
public String getDescription() {
return description;
}
@Override
public void setDescription(String description) {
this.description = description;
}
}
@MappedSuperclass
public abstract class CategoryLang implements CategoryInt{
private int category_id;
private String name;
private String description;
private Category category;
@Override
@Id
public int getCategory_id() {
return category_id;
}
@Override
public void setCategory_id(int category_id) {
this.category_id = category_id;
}
@Override
@Size(max = 50)
public String getName() {
return name;
}
@Override
public void setName(String name) {
this.name = name;
}
@Override
@Size(max = 350)
public String getDescription() {
return description;
}
@Override
public void setDescription(String description) {
this.description = description;
}
@Override
@OneToOne(cascade = CascadeType.ALL)
@PrimaryKeyJoinColumn
public Category getCategory() {
return category;
}
@Override
public void setCategory(Category category) {
this.category = category;
}
}
And persistent final classesCode:
@Entity
@Table(name="es_games")
public class GameES extends GameLang implements Serializable {}
@Entity
@Table(name="en_games")
public class GameEN extends GameLang implements Serializable {}
@Entity
@Table(name = "es_categories")
public class CategoryES extends CategoryLang implements Serializable {}
@Entity
@Table(name = "en_categories")
public class CategoryEN extends CategoryLang implements Serializable {}
@Entity
@Table(name="categories")
public class Category implements Serializable {
private Integer id;
private boolean active;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
}
@Entity
@Table(name = "games")
public class Game implements Serializable {
private int id;
private Integer categories_id;
private Date date_start;
private Date date_expire;
private boolean active;
private Integer game_size;
private String position_one;
private String position_two;
private String position_three;
private CategoryInt category;
private GameInt game;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@NotNull
public Integer getCategories_id() {
return categories_id;
}
public void setCategories_id(Integer categories_id) {
this.categories_id = categories_id;
}
@NotNull
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
public Date getDate_start() {
return date_start;
}
public void setDate_start(Date date_start) {
this.date_start = date_start;
}
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
public Date getDate_expire() {
return date_expire;
}
public void setDate_expire(Date date_expire) {
this.date_expire = date_expire;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public Integer getGame_size() {
return game_size;
}
public void setGame_size(Integer game_size) {
this.game_size = game_size;
}
@Size(min = 4, max = 50)
public String getPosition_one() {
return position_one;
}
public void setPosition_one(String position_one) {
this.position_one = position_one;
}
@Size(min = 4, max = 50)
public String getPosition_two() {
return position_two;
}
public void setPosition_two(String position_two) {
this.position_two = position_two;
}
@Size(min = 4, max = 50)
public String getPosition_three() {
return position_three;
}
public void setPosition_three(String position_three) {
this.position_three = position_three;
}
@OneToOne(cascade = CascadeType.ALL)
@PrimaryKeyJoinColumn
public CategoryInt getCategory() {
return category;
}
public void setCategory(CategoryInt category) {
this.category = category;
}
@OneToOne(cascade = CascadeType.ALL)
@PrimaryKeyJoinColumn
public GameInt getGame() {
return game;
}
public void setGame(GameInt game) {
this.game = game;
}
}