Skip to content

Tag: database-connection

Difference between connecting to a database using DriverManager and SpringBoot(Hibernate)

There are 2 ways to connect to a database when developing Java apps. Using DriverManager Connection conn = DriverManager.getConnection(url, name, password); // execute the query. Using application property file in SpringBoot spring.jpa.hibernate.ddl-auto=none spring.datasource.url=jdbc:mysql://localhost:5432/db_name spring.datasource.username=user spring.datasource.password=password Now you can use @Entity annotation on your class to put data into database. My question is how are these 2 ways different. If not

Why do I need Transaction in Hibernate for read-only operations?

Why do I need Transaction in Hibernate for read-only operations? Does the following transaction put a lock in the DB? Example code to fetch from DB: Can I use session.close() instead of tx.commit()? Answer Transactions for reading might look indeed strange and often people don’t mark methods for transactions in this case. But JDBC will create transaction anyway, it’s just