Hibernate not printing 'select' SQL statements
I have a simple code snippet provided below along with the necessary hibernate confi开发者_开发技巧guration. 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.
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.
精彩评论