0

I have a situation where I want to do some DB-related operations in a Java application (e.g. on Eclipse). I use MySQL as a RDBMS and Hibernate as an ORM provider.

  1. I retreive all records using embedded SQL in Java:

//Define conncections ...etc

ResultSet result = myStmt.executeQuery("SELECT * FROM employees");

// iterator

  1. I retreive all records using Hibernate ORM / JPQL:

// Connections,Entity Manager....etc

List result = em.createQuery("SELECT emp FROM Employees emp").getResultList();

// iterator

I know that the RDMS is located on secondary-memory (DISK). The question is, when I get both results back. Where are the employees actually? On the secondary (SM) or on main-memory (MM)?

I want to have at the end two object populations for further testing, one operating on the SM and one on the MM? How is this possible?

Thanks

Frank

1 Answers1

0

Your Java Objects are real Java Objects, they are in (to use your term) MM, at least for a while. The beauty of the Hbernate/JPA programming model is that while in MM you can pretty much treat the objects as if they were any other Java object, make a few changes to them etc. And then at some agreed time Hibernate's persistence mechansim gets them bask to, SM (disk).

You will need to read up on the implications of Sessions and Transactions in order to understand when the transitions between MM and SM occur, and also very importantly, what happens if two users want to work with the same data at the same time.

Maybe start here

It is also possible to create objects in MM that are (at least for now) not related to any data on disk - these are "transient" objects, and also to "disconnect" data in memeory from what's on disk.

My bottom line here is that Hibernate/JPA does remove much grunt work from persistence coding, but it cannot hide the complexity of scale, as your data volumes increase, your data model's complexity grows and your user's actions contend for data you need to do serious thinking. Hibernate allows you to achive good things, but it can't do that thinking for you, you have to make careful choices as your problem domain gets more complex.

djna
  • 54,992
  • 14
  • 74
  • 117