Is this normal? It's the same in the output on the command-line from Jboss AS7, it shows one query for every call to get. First I figured it just showed the queries it would use and then just get the data from the session but looking in the general query log in the MySQL-folder it lists the same queries being done.
I've got one of those HibernateUtil-classes like this:
Code:
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
return new Configuration().configure().buildSessionFactory();
}
catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Then I use it for example like this:
Code:
public class App
{
public static void test()
{
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
Test test = (Test) session.get(Test.class, 1);
session.getTransaction().commit();
}
}
Where Test is a MySQL-table mapped as a class and 1 is just the item's ID in the table. I've tried printing in the buildSessionFactory-function and it's only being called once still there's a new query in the general query log every-time get is called.
Btw, it's the log you turn on with this in MySQL:
Code:
SET GLOBAL general_log = 'ON';