views:

64

answers:

3

I am in need of some further information.

I am developing a small application which will be interacting with a PHP web application. The media server which we are incorporating with is extensible in Java.

I need very little access to the database inside the plugin which we are developing, I only need to view rows in about 10% of the tables. I only need to update data in 1 of the tables.

The schema as a whole is littered with foreign keys, but currently (and there is little chance this changes in the future) I do not need to modify any other information in the databse except for the one column (which is not a foreign key).

I don't really want to model all of these relationships -- as there is no need to.

What is my best bet? Will Hibernate make me map all of these domain objects? Is myBatis (formerly iBATIS) a better choice as the people I am handing off too are more comfortable with SQL? Does it matter which persistence framework I choose -- i.e. are they all going to make me model each of the tables?

These are mySQL InnoDB tables if it makes any difference.

+1  A: 

With Hibernate, you only need to model the objects you will be working with, and the ddl2hbm tool may be able to generate the Java classes for you based on the existing database, depending on if there are foreign keys linking to models you will not be using.

Andy
A: 

I can't really speak about Hibernate, but myBatis won't make you model anything - just create a POJO that contains the properties that you care about, then write mappings (in just straight sql) that map whatever columns from whatever tables you want into your pojo.

Matthew J Morrison
+2  A: 

Hibernate only requires you to map those items which you want to use within the context of your Java application. As a result, you can have objects only mapped to those tables which you desire access from the Java side.

A few caveats for the process though:

  • You will have to model all objects/relationships for all tables with which a given entity table will interact
  • Things could be messy with two programs hitting the database at the same time. While this is an issue that is accounted for and handled by Hibernate for locking, such things tend to fall by the wayside in PHP.
apiri
Due to the caveat of having to model each of the tables involved it was easier to go with myBatis. Unfortunately the tables involved spiral out of control, and that would basically require mapping the entire db, which isn't necessary when I just needed select access on 3 tables and update on 1.
Scott