I'm new to Hibernate and I'm trying to use the latest Hibernate EntityManager code with MySQL in a J2SE environment.
If I persist an object, then query that object, the query return null.
If I persist the object, then flush the entity manager, the query is successfull.
I wasn't expecting to have to flush the entity manager after every persist or remove call.
I've also just discovered that if I wrap the persist in a transaction, then a query works ...
em.getTransaction().begin();
em.persist(user);
em.getTransaction.commit();
Query query = em.createQuery("select user from User as user");
return (List<User>) query.getResultList();
Is there a setting I'm missing, or does this have something to do with the transaction model when running in a J2SE environment?
Bryan
|