I'm developing all of this on a desktop 3.2 Ghz with HT, lots of ram, and the database is installed localy. I'm using hibernate.cfg.xml that's identical to the one in the documentation section 1.2.3 (except for connection string, and turned off show_sql because then it takes like 6 minutes). I notice there's no second level cache...would that slow things down?
Another thing that's memory related is suppose I have two tables with one-to-many relationship. When I query the table on the "one" side of the relationship, will hibernate fill out every entry in the set? That would take up a lot of memory. This is my actual code. There's a 1:N relationship between MachineClass and MachineDataInstance (which then contains all of the info). I check if this record already exists, so I'm interested in some data but not all of it. How much data will Hibernate load when it has "lazy select fetching" turned on by default? Is there a better way of doing this?
Code:
try
{
Object temp = session.createQuery("from MachineClass where Name = ?").setString(0, machineClass.Name).uniqueResult();
if (temp == null) //this class doesn't exist in the database so create everything
{
machineClass.MachineDataInstanceSet.add(machineDataInstance);
session.save(machineClass);
}
else //the info about the machine already exists, so import only the new instance
{
machineClass = (MachineClass) temp;
if (!machineClass.MachineDataInstanceSet.contains(machineDataInstance))
{
machineClass.MachineDataInstanceSet.add(machineDataInstance);
session.save(machineClass);
resultID = machineClass.ID;
}
}
transaction.commit();
}
catch (Exception e)
{
System.out.println(e);
e.printStackTrace();
transaction.rollback();
}
finally
{
session.clear();
session.close();
}