Is it efficient to query \ update the database on every transaction: Java application

I am developing a realtime book management system in java. So I need to save all users, workbooks, transactions in the database (3 table users, workbooks, transactions). For this I have implemented JDBC.

So, I would like to know which one is the best among

1) Query and update the database all the time, let's say I have to authenticate a user from usertable or query a book from a table of books

OR

2) First query the database after starting the application and store the corresponding tables in a Hashset and iterate the HashSet while updating or query and update all the Hashsets in the database at the end of execution.

+3


source to share


1 answer


Gavin King is smiling at you somewhere. There is an ORM (Relational Model Object) tool called Hibernate that was built for exactly the type of use you have. Using Hibernate, you will create Java objects that represent tables, users, workbooks and transactions in your database schema. These objects will update as your business logic runs. You can decide where and when you want to sync with the database by controlling the size and volume of each transaction (session). If you want to sync with the database, you can call the methodflush()



...

The answer to your question is that it depends on many factors. In general, you want to avoid hacking the database, so the size and volume of database transactions needs to be built around it.

0


source







All Articles