• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

New to Hibernate

 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm just reading up hibernate right now, it seems to be pretty cool. I'm updating an application which interact with database. I can't chaneg the database design because other external tools use and update it as well.
The databae contains over 8000 tables, each table definition is the same, with the except of data itself. Each table has about 2000 - 50000 records.
Hibernate was suggested and we are doing reseach right now. I like the idea the that no more JDBC and sql, but from my research, it seems that we have to maintain the mapping files, which is abit too much considering 8000 tables.
If I read the document wrong, please correct me. The last thing I want to do is to getting all the user interface and logic done, then stuck with Hibernate part and realize it's a maintenance nightmare.
Any help is appreciated.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If there really are 8000 (!) tables and they're basically identical except for name and data, I would probably be looking at using a single, parameterized DAO for those tables.
I.e. something like
MyGenericDAO dao = new MyGenericDAO("table7999");
Record record = dao.getRecord(123);
 
Qi Ming Chen
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am also new to hibernate, I have read that if you use xdoclet (hibernatedoclet), it can generate the mapping for you, so in theory,
it can save you a lot of time.
http://xdoclet.sourceforge.net
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, there are 8000 tables, and I can't do anything about it because too many vendors update the tables. I really would hate to write SQL for my application, I'm looking at any other options that can help me to simply the process.
I'm not sure what DAO (Data Access Object?) is.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Adrian Yan:
I'm not sure what DAO (Data Access Object?) is.
Exactly.
If the tables really are identical, it should be possible to write one DAO and parameterize the table name. The SQL would then be constructed dynamically for each new instance of the DAO class with "SELECT * FROM table_" + tableName + " WHERE id = ?", for example
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool, I see it now. That pattern is what I had in mind without knowing it's a pattern . I guess there is no way to avoid SQL now . That's fine, it should work just fine. Thanks for the help guys.
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Adrian Yan:
Cool, I see it now. That pattern is what I had in mind without knowing it's a pattern . I guess there is no way to avoid SQL now . That's fine, it should work just fine. Thanks for the help guys.

Of course there is. However, your requirements don't call for something as sophisticated as Hibernate. When given two choices and all things being equals always choose the simplest option. In this case, the simplest thing appears to be writing a bit of JDBC code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic