-->
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.  [ 3 posts ] 
Author Message
 Post subject: Mapping many-to-many relations with data in the relation tab
PostPosted: Wed May 21, 2008 8:28 am 
Newbie

Joined: Wed May 21, 2008 7:34 am
Posts: 3
Hi

I am trying to develop a webapp with multilanguage support, but I am having problems figuring out how I should map the following database tables structure to java-objects because there is data in the relation table (CategoryTranslation).

DataModel

Category
=======
id (PK)
parent_id (FK) (self reference)
type
sequence


Language
=======
id (PK)
language_code
language


CategoryTranslation
==================
category_id (FK)
language_id (FK)
categoryname_translation

Mapping this relation would be pretty straigt forward if it wasn't for the categoryname_translation column. Any ideas, tips or suggestions would be highly appriciated.


Hibernate version: 3
Name and version of the database you are using: MySql 5


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 21, 2008 9:32 am 
Newbie

Joined: Wed May 21, 2008 6:57 am
Posts: 8
...if you want composite PK...

@Entity
@IdClass(CategoryTranslationId.class)
public class CategoryTranslation

@Id
@Column(insertable=false, updatable=false)
private Long category_id;
@Id
@Column(insertable=false, updatable=false)
private Long translation_id;

@ManyToOne
@JoinColumn(name="category_id", insertable=false, updatable=false)
private Category category;

@ManyToOne
@JoinColumn(name="translation_id", insertable=false, updatable=false)
private Translation translation;

//...


you will need to implement idclass, but that's trivial

maybe it's smarter tho to add semantics-free PK


Top
 Profile  
 
 Post subject: The solution is of course obvoius.... now ;)
PostPosted: Wed May 21, 2008 10:02 am 
Newbie

Joined: Wed May 21, 2008 7:34 am
Posts: 3
Sambolino wrote:
...if you want composite PK...

@Entity
@IdClass(CategoryTranslationId.class)
public class CategoryTranslation

@Id
@Column(insertable=false, updatable=false)
private Long category_id;
@Id
@Column(insertable=false, updatable=false)
private Long translation_id;

@ManyToOne
@JoinColumn(name="category_id", insertable=false, updatable=false)
private Category category;

@ManyToOne
@JoinColumn(name="translation_id", insertable=false, updatable=false)
private Translation translation;

//...


you will need to implement idclass, but that's trivial

maybe it's smarter tho to add semantics-free PK


Thank you very much, it is pretty obvious now that I was stuck in the old JDBC way of thinking.... I do of course need a CategoryTranslation class. And adding a semantics free PK is no problem. Thank you for setting my thoughts straight ;)


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