1

I have a simple code snippet provided below along with the necessary hibernate configuration. The issue is all the 'insert' statements are being printed but 'select' statements are not printed.

Session sess = session.openSession();
Transaction tx = sess.beginTransaction();
Address addr = new Address();
addr.setStreet("street");
Employee pojo = new Employee();
pojo.setName("XYZ");
pojo.setAddress(addr);
System.out.println("ID " + pojo.getId());
sess.saveOrUpdate(pojo);
tx.commit();
session.close()

The above code prints 'insert' statements in standard output

Session sess = session.openSession();
Transaction tx = sess.beginTransaction();
Employee pojo = (Employee) sess.get(Employee.class, 1);
System.out.println(pojo.getName());
System.out.println(pojo.getAddress().getStreet());
tx.commit();
session.close();

The above code does not print the 'select' statement. I have tried using load() instead of get(), but the result is the same.

This configuration is available in hibernate configuration.

<property name="show_sql">true</property>

Thanks in advance.

1 Answer 1

2

If you have second level cache enabled, selects will not be executed and value will be taken from cache instead. Try to read data that is already in DB rather than what you have just inserted. I assume that you first do insert and then read it right after.

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

2 Comments

Oh Thanks. Which configuration should I change to disable second level cache? Yes, I do an insert and then read it.
I used the following change in the config file. <property name="cache.use_second_level_cache">false</property>. I got the following line printed in the console. Second-level cache: disabled .But the 'select' statement is not printed.

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.