Talon06
Talon06

Reputation: 1796

Java H2 Database Framework

I know this is a newb question, but that's what I am so here goes. I am writing an application in java that has a lot of H2 database queries so far I have written methods that pull the data I need from the database with queries, because this is the only way I know how. My question is, is there an easier way to go about getting data from my database that would be more efficient and make things less work. In my research Spring does something like this, but if it does I have been unable to find good information on how to implement it.

Thanks,

Upvotes: 2

Views: 527

Answers (3)

Renat Gilmanov
Renat Gilmanov

Reputation: 17895

I would say there is even better approach called Java Persistence API. It will make your code ORM agnostic and provide some flexibility.

JPA 2.0 is quite rich and will satisfy all your needs. So I do not think you should use Hibernate directly, instead you should try to use JPA where you can. Please note, Hibernate is JPA 2.0 provider.

Please see the following example Creating Good DAOs with Hibernate 3.5 and JPA 2.0 Annotations

Upvotes: 1

bjedrzejewski
bjedrzejewski

Reputation: 2436

I am also using H2 rather heavily in a large environment. My advice is to use JPA and particularly Hibernate as it is one of the most popular implementation.

What you want to avoid is writing native sql as if you are going to change a database (if you are) you will run into numerous problems with native sql. JPA solves it by defining JPQL which is like SQL, but will work on any database.

Another great benefit from hibernate is the possibility of using L2 cache which can speed up your application drasticaly.

The last benefit is perhaps most relevant to you- it may take you slightly longer to set up, but once its there, it is much easier to work with the database from pure java.

Upvotes: 0

Thomas Mueller
Thomas Mueller

Reputation: 50127

There are many options. As ShyJ wrote, Spring Data JPA is one. Many people use Hibernate. There are other libraries you could use, for example SimpleORM.

But I wonder if "which one is better" is the right type of question for StackOverflow. There are many ways to do it "right", and many things to consider.

Upvotes: 0

Related Questions