-->
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.  [ 9 posts ] 
Author Message
 Post subject: HOW can I make a class associate with multi-table DYNAMIC!
PostPosted: Sat Dec 06, 2003 7:31 am 
Newbie

Joined: Sat Dec 06, 2003 7:21 am
Posts: 4
It is a big problem for me.

my project is a refactoring project to a old system.
in the old system, we create a table by each year.

such as: TBL_NEWS_2003, TBL_NEWS_2002

so when we need search in years, we use UNION to select from all table.

BUT how can i do this in hibernate??

I create a class named: News,
and , actually I must make a News.hbm.xml for it.
and i wrtie table name in the XML.

I need associate the New.class to multi-table
when i query some news, i can specify a tablename or modualname parameter to the session and get the same class from different table.

can i make myself understand?

I NEED HELP.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 06, 2003 8:16 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Unions are not doable AFAIK

Try to do this kind of mapping:
Create a News class, create News2002, News2003 as subclasses.
Map as table-per-concrete class (map News2002 and News 2003 but not News). And play with that.

This solution has many drawbacks, and probably don't be appropriate in your case.

Submit a request to JIRA for you initial feature, Gavin will tell you if you can expect that in a future Hibernate.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 06, 2003 9:42 am 
Newbie

Joined: Sat Dec 06, 2003 7:21 am
Posts: 4
epbernard wrote:
Unions are not doable AFAIK

Try to do this kind of mapping:
Create a News class, create News2002, News2003 as subclasses.
Map as table-per-concrete class (map News2002 and News 2003 but not News). And play with that.

This solution has many drawbacks, and probably don't be appropriate in your case.

Submit a request to JIRA for you initial feature, Gavin will tell you if you can expect that in a future Hibernate.



I don't know what's JIRA??
how can i contact Gavin to suggest my advice as below?

When one develop a website such as a news website.
It its very easy to consider making a generic News.class to
fit for all kinds of news.
eg. A news may have title, content, date ...

so we develop a News.class.
but we have different news, like entertaiment, sport, government, techinical .....

so, we must have dynamically mapping to News.class

News.class should associate to several *.hbm.xml file, each file figure to a table.
like News.sport.hbm.xml, News.entertaiment.hbm.xml

(May be we can specify the different table name just in the filename)

and the Configuaration can read all xml
and one can query News.class in all different table or only one table.

That's what i except mostly of the future hibernate.


Top
 Profile  
 
 Post subject: Re: HOW can I make a class associate with multi-table DYNAMI
PostPosted: Sat Dec 06, 2003 10:07 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
ibingyun wrote:
so when we need search in years, we use UNION to select from all table.
BUT how can i do this in hibernate??


CREATE VIEW AS ...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 06, 2003 10:32 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Well I don't understand your pb. You told me you where in a 1 table per year issue, and then you seems to have simple table-per-hierarchy will.

Map news then map subclasses of News (SportNews, etc..) as <subclass> of News. Hibernate auready do that.

JIRA is the issue tracking facility.
http://opensource.atlassian.com/projects/hibernate/secure/Dashboard.jspa or the left link in Hibernate web site.
But clarify your though before posting an enhancement request.

Quote:
CREATE VIEW AS ...

I'm not familiar with all DBMS but I'm not sure this kind of VIEW be updateable/ insertable.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: HOW can I make a class associate with multi-table DYNAMI
PostPosted: Sat Dec 06, 2003 11:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Map your class to the current year table, and then just use createSQLQuery() to write your own custom union query to read from all tables.

This will work as long as you only want to add/update into the current year table and just need to read from the past.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Still not work
PostPosted: Sat Dec 06, 2003 11:53 am 
Newbie

Joined: Sat Dec 06, 2003 7:21 am
Posts: 4
max wrote:
Map your class to the current year table, and then just use createSQLQuery() to write your own custom union query to read from all tables.

This will work as long as you only want to add/update into the current year table and just need to read from the past.


Thank's max. Your advice solve part of my problem.

but the BIGGEST problem is, My recently year table is create by program automatic. I can not have a PO class to map it.

So I'd like to suggest to Hibernate group adding a dynamic table name mapping function.

by epbernard's method:
I use News.class' subclass SportNews, It's a good solution for the System
not creating table by program itself. It's fit for static tables.

I heard that Gavin King said a custom ClassPersister can deal with the dynamic table name problem.

But ... big trouble...


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 07, 2003 3:49 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Common solution for this kind of problems are views.
It is possible to use system tables for metadata, stored procedures, query rewrite to make logical view of data.
But it is very common to ignore RDMS features and to handle logical view of data in application too :)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 07, 2003 4:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
btw. this precise usecase is now solvable via the new "entity-name" feature in v22branch in hibernate cvs!

Look at the devel-mailing list for details ;)

_________________
Max
Don't forget to rate


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