I know!! It's probably a elemantary flaw. The SQL output looks like this:
Hibernate: insert into person (department, priviliges, position, password, emailAddress, userName, name, address, phoneNo, subclass, personID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, 'U', ?)
Hibernate: insert into person (department, priviliges, position, password, emailAddress, userName, name, address, phoneNo, subclass, personID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, 'U', ?)
I don't know why hibernate prints question marks except for on my discriminator-value, but at least the real values appear in the table. I get two objects in to the database, but when i run main again, with different objects, it overriders the existing objects..
This is my class with a static method to get a Session-object, taken from some hibernate example. Is it ok?
package utilities;
import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;
public class HibernateUtilities {
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (HibernateException ex) {
throw new RuntimeException("Exception building SessionFactory: " + ex.getMessage(), ex);
}
}
public static final ThreadLocal local = new ThreadLocal();
public static Session currentSession() throws HibernateException {
Session session = (Session) local.get();
// Open a new Session, if this Thread has none yet
if (session == null) {
session = sessionFactory.openSession();
local.set(session);
}
return session;
}
public static void closeSession() throws HibernateException
{
Session session = (Session) local.get();
local.set(null);
if (session != null)
session.close();
}
}
|