-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to annotate one entity that is populated from two table.
PostPosted: Wed Sep 27, 2006 1:29 am 
Beginner
Beginner

Joined: Sat Oct 08, 2005 2:13 am
Posts: 47
Hello

Hibernate version: 3.1

Mapping documents: annotation

Code between sessionFactory.openSession() and session.close():
using getHibernateTemplate() method of Spring framework


Name and version of the database you are using:MySql 4.x


--------------------
We have faced a problem in our enterprise project and we think it could be resolved by Hibernate. the problem is that our project is supporting many languages, in fact, our database designed to support this feature. to enagae this feature we have two method to implementing the tables:
(in order to be clear I am using Employee table as an example)

1. break a table into two tables, one contains locale-independent and the other locale-dependent informations.

a table, say, "Employee":
Code:
Employee (id , birthdate, ssn, employment_type)

and locale-dependent table, say, EmployeeLocale
EmployeeLocale (id, locale_id, given_name, family,....)


2. another way is to seperate locale-dependent information in different tables:

Code:
Employee (id , birthdate, ssn, employment_type)

EmployeeEnglish (id, given_name, family,....)
EmployeeFrench (id, given_name, family,....)
EmployeeSpanish (id, given_name, family,....)
....


if information are very huge, maybe the second one has better performance.

any way, the problem comes out when designing the entities and/or value objects with Hibernate. according to first method, we have a Class Employee and a Class EmployeeLocale and they have one-to-many relationship with each other. this is not good when you are working with a big project. in order to access locale-dependent informations you shoud get the Employee and then get its collection, say, "employeeLocales" and in that collection there is only one record because you requested it ,for example, with French locale. in the other hand, when you want to persist some information you should initialize the collection and then insert an instance of EmployeeLocale class into it.

if you opt the second method, it has some other problem.
first off, you have to create a new entity class for every locale (or every table you create) and they have the same attributes and fields (data redundancy in designing entities not tables).
in addition, when insetrting, for example, a new Employee in french, you should use many "if then else" statements in your codes to check if it is french then instantiate EmployeeFrench and so on.

however, it will resolved using the design patterns. We are using some workaround to solve this problem, however, we had to get away some features of Spring framework like IoC. We have defined an Interface, say, Employee and an Abstract class, say, BaseEmployee that implements only locale-independent attributes and other classes that extends from that abstract class and contains locale-dependent info.
and finally, we used the Command Pattern to manage the DAO classes, so, our developers only know the Employee interface and an manager that returns appropriate DAO to interact with database, of course, passing an localeId is necessary here.

is ther any way to have only one Entity, say, Employee and whenever the client (or programmer) request an specific employee with a particular locale then the same Employee being populated. please note, it may be added a new locale and also new table to the database structure so we should not change our entire codes ;)


any suggestion or comment will be appreciated.
Thank you in advance and wish you success.

Regards
M.Norouzi


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 11:20 am 
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
or
http://blog.hibernate.org/cgi-bin/blosxom.cgi/2004/08/10#v3-filters

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 30, 2006 4:19 am 
Beginner
Beginner

Joined: Sat Oct 08, 2005 2:13 am
Posts: 47
Dear Emmanuel,

thanks for your reply. I have read both solution "filters" and "Custom Types". but each has their own problem and doesnt obviate our problem.

1. using custom types:
first off, Gavin's solution is using Hibernate's second-level cache, and he stated this is very efficient but our table structures are not as simple as a Category and Label, we have patient table with more than maybe 30 million records and this is just one table for patient. if we consider other tables the numbers are very big.

another problem is that the user who inserting the data may use english or any other language and we dont know when and which language they will use so we always should be concern about updating the cache whenever some one insert a record.

2. using filters: this is good just for filtering the locale-dependent data but
our problem still alive.

In other words, our problem is, we need to join both tables main table and the table contains locale information. but we need to have just one entity, say "Patient" not two entities "Patient" with a collection of "PatientLocale".

I think this should be a feature in Hibernate. if we could define for example a template entity or an Interface as an Entity and say the hibernate, please populate this interface or template class instead of those two entities (Patient and PatientLocale) everything is right.



I put an issue in Hibernate JIRA but unfortunately, they reject that. I get very happy when see you answered me. I am looking forward to know your idea on this.
[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 04, 2006 1:22 am 
Beginner
Beginner

Joined: Sat Oct 08, 2005 2:13 am
Posts: 47
any idea?


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