-
1. Re: Problems with EntityManager in SeamTest
cpopetz Mar 27, 2008 7:44 PM (in response to boopet)I coincidentally just ran into this today as well. You need:
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
in your persistence.xml. I've never had that in my persistence.xml before, and it used to work in test land without it, and it definitely works in-container without it, so I don't know what changed. I'm guessing an upgrade to seam at some point pickup up a new version of hibernate in hibernate-all, and maybe hibernate started requiring it. In any case, a quick check of the hibernate docs says that we should have this in our persistence.xml to use hibernate with JTA.
-
2. Re: Problems with EntityManager in SeamTest
boopet Mar 28, 2008 7:58 PM (in response to boopet)thanks for the hint! that really helped.
But now it seems its not possible to persist data.
When persisting and trying to fetch with the entitymanger, nothing is returned as result.the old way using
em.getTransaction().begin(); .. em.getTransaction().commit();
does no longer work now, because it says:
java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction() at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:317)
thanks for any advice.
regards,
norbert -
3. Re: Problems with EntityManager in SeamTest
pmuir Mar 29, 2008 7:29 PM (in response to boopet)Use an integration test, rather than trying to test persistence in a unit test.
-
4. Re: Problems with EntityManager in SeamTest
boopet Mar 30, 2008 4:11 PM (in response to boopet)thanks pete, this seems to be the right way for doing that.
i have restructured my tests and now want to access the seam components that way:@Test public void testCreateUser() throws Exception { new ComponentTest() { protected void testComponents() throws Exception { User currentUser = (User) Component.getInstance("QAdsUser"); UserService service = (UserService) Component.getInstance("userService");
which brings up a NullPointerException when trying to access the components. I dont want to use the EL way to test basic functionality of the services.
is there a way to get the components directly from the seam context inside a integration test?
thanks
norbert -
5. Re: Problems with EntityManager in SeamTest
pmuir Mar 31, 2008 12:15 PM (in response to boopet)Use a FacesRequest.
-
6. Re: Problems with EntityManager in SeamTest
jwi.jwi.informationsdesign.de Apr 4, 2008 12:41 PM (in response to boopet)...have stumbled upon the same problem.
But no data get persistet, although using a FacesRequest.
excerpt from SQl-logging (no inserts/updates !?)
Hibernate: select SEQ_GESELLSCHAFT.nextval from DUAL Hibernate: select entityfiel0_.ID as ID4_, entityfiel0_.cat as cat4_, entityfiel0_.dimType as dimType4_, entityfiel0_.fieldname as fieldname4_, entityfiel0_.fieldtype as fieldtype4_, entityfiel0_.relatedDimType as relatedD6_4_, entityfiel0_.standardSelection as standard7_4_, entityfiel0_.subsetType as subsetType4_, entityfiel0_.systemField as systemFi9_4_, entityfiel0_.textLength as textLength4_, entityfiel0_.valueList as valueList4_ from FIELDMETA entityfiel0_ where entityfiel0_.dimType='GESELLSCHAFT' Hibernate: select fieldvalue0_.fieldMeta_ID as fieldMeta3_1_, fieldvalue0_.ID as ID1_, fieldvalue0_.ID as ID2_0_, fieldvalue0_.fieldMeta_ID as fieldMeta3_2_0_, fieldvalue0_.value as value2_0_ from FIELDVALUEITEM fieldvalue0_ where fieldvalue0_.fieldMeta_ID in (?, ?) Hibernate: select SEQ_JOURNALDATA.nextval from dual Hibernate: select SEQ_JOURNALDATA.nextval from dual
-
7. Re: Problems with EntityManager in SeamTest
jwi.jwi.informationsdesign.de Apr 4, 2008 12:43 PM (in response to boopet)as you can see, the sequences (it's an Oracle10) for inserting 2 new records are used (native SQL query), but no line
insert ...
is logged.?
-
8. Re: Problems with EntityManager in SeamTest
ajordens.adam.jordens.org Jun 18, 2008 11:10 PM (in response to boopet)I use Maven and have my EJBs and actions separated into different artifacts.
I'm able to override the persistence.xml for the ejb artifact and do persistence testing without problem independent of the SeamTest.
<persistence-unit name="testDB"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <class>...</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/> <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/> <property name="hibernate.connection.username" value="sa"/> <property name="hibernate.connection.password" value=""/> <property name="hibernate.connection.url" value="jdbc:hsqldb:."/> <property name="hibernate.hbm2ddl.auto" value="create-drop"/> <property name="hibernate.show_sql" value="true"/> </properties> </persistence-unit>
Tests look similar to the following (minus some abstractions to create the entity manager in a @BeforeSuite and cleanup in an @AfterSuite).
EntityManagerFactory factory = Persistence.createEntityManagerFactory("testDB"); EntityManager em = factory.createEntityManager(); em.getTransaction().begin(); EntityA entity = new EntityA(); entity.setLabel("Foo"); em.getTransaction.commit(); Assert.assertNotNull(entity.getId()); em.close() factory.close()
-
9. Re: Problems with EntityManager in SeamTest
btonez Jun 19, 2008 6:29 AM (in response to boopet)I had a similar problem and solved it by changing the transaction type from default JTA (evil) to RESOURCE_LOCAL (Seam-friendly):
<persistence-unit
name="project"
transaction-type="RESOURCE_LOCAL"> -
10. Re: Problems with EntityManager in SeamTest
ellis2323.lmallet.oxalya.com Jun 21, 2008 2:45 AM (in response to boopet)No Need to change the persistence.xml or whatelse.
By default, it seems that in a SeamTest, there is no Transaction created. Because of JTA we can't use getTransaction. So i created one with UserTransaction class.@Name("testView") public class TestView extends SeamTest { @Test public void testDeleteView() throws Exception { new ComponentTest() { protected void testComponents() throws Exception { UserTransaction tx = Transaction.instance(); tx.begin(); RPBElement rPBElement = (RPBElement)Component.getInstance("rPBElement"); List<RPMCriterium> criteria = new ArrayList<RPMCriterium>(); criteria.add(new RPMCriterium("Type", "testDeleteView", Comparator.EQ)); RPMView viewA = rPBElement.createViewExt("View testDelete", criteria); tx.commit(); tx = Transaction.instance(); tx.begin(); rPBElement.deleteViewExt(viewA.getId()); tx.commit(); } }.run(); } }
You could use your entityManager in this code with :
EntityManager entityManager = Component.getInstance("entityManager");
-
11. Re: Problems with EntityManager in SeamTest
bonissauro Apr 22, 2011 10:24 AM (in response to boopet)Great, Clint !!!
That was just what I needed !!!
10x a lot