views:

200

answers:

3

Hello!

I've got some tables in an existing database and I want to map them to a Java object. Actually it's one table that contains the main information an some other tables that reference to such a table entry with a foreign key.

I don't want to store objects in the database, I only want to read from it. The program should not be allowed to apply any changes to the underlying database.

Currently I read from the database with 5 JDBC sql queries and set the results then on an object.

I'm now looking for a less code intensive way. Another goal is the learning aspect. Is Hibernate suitable for this task, or is there another ORM framework that better fits my requirement?

+2  A: 

Go for Hibernate. It is suitable, very popular and learning to use this framework is not a waste of time at all.

Andreas_D
+1  A: 

I've got some tables in an existing database and I want to map them to a Java object. Actually it's one table that contains the main information an some other tables that reference to such a table entry with a foreign key.

Looks like a very standard schema, Hibernate should be able to deal with it without problems.

I don't want to store objects in the database, I only want to read from it. The program should not be allowed to apply any changes to the underlying database.

Hibernate supports "immutable" entities (immutable entities may not be updated by the application, see the @Immutable annotation).

Currently I read from the database with 5 JDBC sql queries and set the results then on an object.

I could say if it ain't broken, don't fix it but...

I'm now looking for a less code intensive way. Another goal is the learning aspect. Is Hibernate suitable for this task, or is there another ORM framework that better fits my requirement?

If learning is a part the motivation, then it can make sense. As I said, I think that Hibernate will be able to handle your model without any problems (when a database is heavily denormalized or when you have a lot of stored procedures, a data-mapper like iBATIS might be better but it isn't the case here) and porting your application to Hibernate/JPA should be pretty easy. On top of that, you'll get a few bonus things like lazy-loading, 2nd level and query caching.

Pascal Thivent
+1  A: 

If you are looking for a simpler solution to hibernate, you can check out ORMLite which is a [much] simple ORM package. I've used it to read in objects from pre-existing SQL tables with great success.

http://ormlite.sourceforge.net/

Gray