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?
Looks like a very standard schema, Hibernate should be able to deal with it without problems.
Hibernate supports “immutable” entities (immutable entities may not be updated by the application, see the
@Immutableannotation).I could say if it ain’t broken, don’t fix it but…
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.