-->
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.  [ 7 posts ] 
Author Message
 Post subject: I18N Mapping with Hibernate
PostPosted: Thu May 15, 2008 8:52 am 
Newbie

Joined: Thu May 15, 2008 8:31 am
Posts: 3
Is there a way to map this schema by using hibernate annotations?

Image


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 15, 2008 9:30 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Of course.
I would advise you to use reverse engineering from an existing schema,
otherwise it could be tricky if you are new to annotations.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 16, 2008 4:24 am 
Newbie

Joined: Thu May 15, 2008 8:31 am
Posts: 3
Thank you; but I want to map it to a specific class structure;
Lets take just the item and the ItemLocale classes;
suppose I have defined the classes like this:

public class Item{
private Integer id;
private Integer SellerId;
private Integer Price;

// Geters and Setters
}

and the ItemLocale class as follows (extending Item class)

public class ItemLocale extends Item {
private Culture culture;
private String name;
private String description;

// Geters and Setters
}

is it possible to map this to the db schema; the reverse Enginnering tool does not help in this case :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 16, 2008 6:48 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Are you really sure ItemLocal has to extend Item?
This is not reflected by your schema, you're going to inherited the other properties too.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 16, 2008 8:39 am 
Newbie

Joined: Thu May 15, 2008 8:31 am
Posts: 3
The class structure is not really different than the schema. If you have the following Annotation on the Item class; then you get the schema I mentioned:
@Inheritance(strategy=InheritanceType.JOINED)

but the problem is that the ItemLocale class has a different primary key (keys) than ist superclass (Item).

Is there a way to override the primary keys? How can I map the schema to this class structure?

thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 16, 2008 9:05 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Ok, now I understand you problem better;
unfortunately I don't have an answer, I should try with @IdClass, but I'm not sure it is possible.

You can't change either the classes or the shema? I've had a similar problem also for i18N
but I solved it using Maps; you could add something like this to your Item:

Code:
Map<Culture,String> getLocalizedName();
or
Code:
Map<Culture,ItemLocale> getItemLocale();

The second results in your mapping, but I prefer the first one as it generates java code I like better. I don't think you could make ItemLocale extend Item in this case though.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 16, 2008 10:17 am 
Newbie

Joined: Tue May 06, 2008 10:17 am
Posts: 2
Location: Canary, Spain
Sorry if I am in the worst, but I think that you don´t do it. For get it you should duplicate in the database every field of the table Item.

But if you what to get the fields of Item you should to map this on Item_Locale

Code:
@ManyToOne (
   fetch = FetchType.EAGER,          <-- Request the data of the Item
        cascade = CascadeType.SAVE_UPDATE <-- Save the changes of the Item
    )
    @JoinColumn(
        name = "ItemId",
        referencedColumnName = "ItemId",
        insertable = false,
        updatable = false
    )
    Item item;

Then you only need to get the Item date with the getter method.

_________________
Sorry for my english, but I'm Spanish and I don´t speak english very well.

If it is usefull, please rate!. :)


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