entityManager.persist(Object) not working?
smeaggie Mar 29, 2007 10:01 AMHello all, I have a small question I don't know if the Seam forum is the right place to post, but I use a seam managed entity manager and it's behaviour puzzles me... A very simplified sitation sketch:
data class:
@Entity() @Name("data") public class Data implements Serializable { // field declarations here (plus getters and setters) }
Bean code:
@Name("importService") @Scope(ScopeType.CONVERSATION) public class ImportService implements Serializable { @In() private EntityManager entityManager; public void parse(Document d) { Data data = new Data(); // Document d is an XML file, wich is parsed, all values are set in // the data object this.entityManager.persist(data); // I hoped the data would be saved by now... } }
Also I have this in components.xml:
<core:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/MyEntityManagerFactory"/>
And persistence.xml:
<?xml version="1.0" encoding="UTF-8"?> <!-- Persistence deployment descriptor for dev profile --> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="MyDBUnit"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/MyDatasource</jta-data-source> <properties> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="hibernate.cache.use_query_cache" value="true"/> <property name="hibernate.show_sql" value="true"/> <property name="jboss.entity.manager.factory.jndi.name" value="java:/MyEntityManagerFactory"/> </properties> </persistence-unit> </persistence>
On deploy time, the database table Data is created perfectly, I get all the SQL statements on my console log. No problem. If I manually insert data, I can query for the data using this.entityManager.createQuery("from Data data"); even INSIDE the parse method of the bean, again I see the SQL statement in my console log. But on the entityManager.persist(data) call, there's no SQL statement executed. I surrounded the call with a try { ... } catch (Exception e) { ... } block but there are NO exceptions thrown. Just no data is saved :(
Can someone help me with this please? I really don't understand why data is not saved...!