File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes New to Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "New to Hibernate" Watch "New to Hibernate" New topic
Author

New to Hibernate

Adrian Yan
Ranch Hand

Joined: Oct 02, 2000
Posts: 688
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

Joined: Jan 23, 2002
Posts: 11962
    
    5
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);


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Qi Ming Chen
Greenhorn

Joined: Feb 13, 2004
Posts: 1
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

Joined: Oct 02, 2000
Posts: 688
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

Joined: Jan 23, 2002
Posts: 11962
    
    5
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

Joined: Oct 02, 2000
Posts: 688
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

Joined: Jul 18, 2001
Posts: 2712
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: New to Hibernate