2

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,

4
  • 2
    What do you mean by more efficient? Is it the efficiency of writing the code (i.e. the time needed to write the code) or the efficiency of getting the data off the database? Commented Nov 21, 2012 at 15:34
  • I guess either I just want to make sure I am doing things right. As of right now seems to me like I am doing a lot of boiler plate coding. Commented Nov 21, 2012 at 15:37
  • 2
    Then you're probably looking for something like Spring Data JPA Commented Nov 21, 2012 at 15:42
  • JPA is the way to go. Several people have mentioned hibernate. Eclipslink is quite good too. Commented Nov 22, 2012 at 6:49

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.