1 2 Previous Next 16 Replies Latest reply on Jan 24, 2006 9:50 AM by gavin.king

    seam-manages persistance (i'm going bananas)

    emsa

      Again - I have this is seam.properties:

      org.jboss.seam.core.init.managedPersistenceContexts em
      em.persistenceUnitName java:/EntityManagerFactories/testDatabase


      em is created:
      [Component] Component: em, scope: CONVERSATION, type: JAVA_BEAN, class: org.jboss.seam.core.ManagedPersistenceContext


      Doing this:
      @In(create=true)
       private EntityManager em;


      results in:
      Caused by: javax.ejb.EJBTransactionRolledbackException: null; CausedByException is:
       EntityManagerFactory not found


      Looking up 'java:/EntityManagerFactories/testDatabase' by hand gives a 'org.jboss.ejb3.entity.InjectedEntityManagerFactory'

      Still using beta1, whats is wrong???

      Thanks,
      /Magnus

        • 1. Re: seam-manages persistance (i'm going bananas)
          gavin.king

          java:/EntityManagerFactories/testDatabase is not the persistence unit name. It is the JNDI name. The persistence unit name is testDatabase.

          Seam beta2 has an .jndiName setting as an alternative.

          • 2. Re: seam-manages persistance (i'm going bananas)
            emsa

            Doh! Yes ofcourse - this is what happens when you just read and don't think!

            Thanks for all your help Gavin!!!

            • 3. Re: seam-manages persistance (i'm going bananas)
              gavin.king

              It looks like this was actually wrong in the docs. I had better fix that.

              • 4. Re: seam-manages persistance (i'm going bananas)
                gavin.king

                It's my fault. The docs said one thing, the code another, and the defaulting was all set up to work well with an older draft of the EJB spec. I think other people have complained about this stuff and I just didn't understand what they were trying to say. Ugh.

                So, I have rationalized this stuff as follows:

                org.jboss.seam.core.init.managedPersistenceContexts em
                em.persistenceUnitJndiName java:/EntityManagerFactories/testDatabase


                Means look in "java:/EntityManagerFactories/testDatabase" for the EMF.


                org.jboss.seam.core.init.managedPersistenceContexts testDatabase


                Means look in "java:/testDatabase" for the EMF.

                There is now no longer any support for just specifying the persistenceUnitName ('cos of changes to the EJB3 spec).

                The same thing has been done for managed Hibernate sessions.

                In CVS.

                • 5. Re: seam-manages persistance (i'm going bananas)
                  gavin.king

                  And I have mentioned the org.jboss.entity.manager.factory.jndi.name thing in the Seam docs.

                  • 6. Re: seam-manages persistance (i'm going bananas)
                    andrew.rw.robinson

                    Okay, I am in this boat of having endless problems. I am not sure what I am doing wrong, but it seams like the data source isn't even getting created.

                    Environment desired:
                    Tomcat 5.5
                    Embedded EJB3 container (I am using the one from seam now and not the updated one as I had problems -- in another post)
                    Seam extended transaction manager
                    PostgreSQL managed datasouce

                    Heirarchy:

                    test-seam.war
                     WEB-INF/
                     web.xml
                     faces-config.xml
                     lib/
                     test-seam.jar
                     META-INF/
                     log4j.properties
                     persistence.xml
                     classes/
                     jboss-beans.xml
                     seam-jndi.properties
                     seam.properties


                    faces-config.xml:
                    ...
                    <lifecycle> <phase-listener>org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener</phase-listener>
                    </lifecycle>
                    ...


                    web.xml:
                    <!-- Database setup -->
                     <context-param>
                     <param-name>org.jboss.seam.core.init.managedPersistenceContexts</param-name>
                     <param-value>entityManager</param-value>
                     </context-param>
                    
                     <context-param>
                     <param-name>entityManager.persistenceUnitJndiName</param-name>
                     <param-value>java:/EntityManagerFactories/testDatabase</param-value>
                     </context-param>
                    


                    jboss-beans.xml:
                    <?xml version="1.0" encoding="UTF-8"?>
                    
                    <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
                     xmlns="urn:jboss:bean-deployer">
                    
                     <bean name="testDatasourceBootstrap"
                     class="org.jboss.resource.adapter.jdbc.local.LocalTxDataSource">
                     <property name="driverClass">org.postgresql.Driver</property>
                     <property name="connectionURL">jdbc:postgresql://localhost/testdb</property>
                     <property name="userName">test</property>
                     <property name="password">test</property>
                     <property name="jndiName">java:/testDatasource</property>
                     <property name="minSize">0</property>
                     <property name="maxSize">10</property>
                     <property name="blockingTimeout">1000</property>
                     <property name="idleTimeout">100000</property>
                     <property name="transactionManager"><inject bean="TransactionManager" /></property>
                     <property name="cachedConnectionManager"><inject bean="CachedConnectionManager" /></property>
                     <property name="initialContextProperties"><inject bean="InitialContextProperties" /></property>
                     </bean>
                    
                     <bean name="testDatasource" class="java.lang.Object">
                     <constructor factoryMethod="getDatasource">
                     <factory bean="testDatasourceBootstrap" />
                     </constructor>
                     </bean>
                    
                    </deployment>


                    seam-jndi.properties:
                    ava.naming.factory.initial org.jnp.interfaces.LocalOnlyContextFactory
                    java.naming.factory.url.pkgs org.jboss.naming:org.jnp.interfaces


                    seam.properties is empty

                    persistence.xml:
                    <persistence>
                     <persistence-unit name="testDatabase">
                     <provider>org.hibernate.ejb.HibernatePersistence</provider>
                     <jta-data-source>java:/testDatasource</jta-data-source>
                     <properties>
                     <property name="hibernate.dialect"
                     value="org.hibernate.dialect.PostgreSQLDialect" />
                     <property name="connection.release_mode">after_statement</property>
                     <property name="hibernate.default_schema">public</property>
                     <property name="hibernate.transaction.manager_lookup_class"
                     value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
                     <property name="hibernate.transaction.flush_before_completion" value="true"/>
                     <property name="hibernate.show_sql" value="true"/>
                     <!--property name="jboss.entity.manager.factory.jndi.name"
                     value="TestEntityManager"/-->
                     </properties>
                     </persistence-unit>
                    </persistence>
                    


                    catalina.out:
                    NFO 22-01 23:12:08,552 (Ejb.java:startup:39) -starting the embedded EJB container
                    INFO 22-01 23:12:11,517 (LocalTxDataSource.java:bindConnectionFactory:117) -Bound datasource to JNDI name 'java:/DefaultDS'
                    INFO 22-01 23:12:12,488 (Initialization.java:init:92) -done initializing Seam
                    


                    There is one session bean in the test-seam.jar as well, and it isn't being recognized either. Not sure what is going on, any help is appreciated as I wasted 3 hours on this. Thanks

                    • 7. Re: seam-manages persistance (i'm going bananas)
                      gavin.king

                      You need the following line in persistence.xml:

                      <property name="jboss.entity.manager.factory.jndi.name"
                       value="java:/EntityManagerFactories/testDatabase"/>


                      This *used* to be implicit in the previous version of EJB3, but since then the spec changed and it is no longer implicit. I have already updated the Seam docs to reflect the fact that this is now required.

                      Yes. make sure you are only using exactly the jars that are in CVS right now.

                      • 8. Re: seam-manages persistance (i'm going bananas)
                        andrew.rw.robinson

                        I added that, but still having the same problem. What is interesting to me is that the output to the log shows the DefaultDS being bound into the JNDI tree, but not my testDatasource being bound. It is as if the jboss-beans.xml and the persistence.xml are not even being found by the EJB3 container. There are no exceptions or any logging to even give me a hint.

                        If I try to hit the web page, I get a SerlvetException of "Could not start transaction" and NamingException of "Cannot create resource instance". I don't think these are the problem, it just seams as if the EJB3 isn't finding my datasource or cannot set it up and isn't printing anything to the console.

                        • 9. Re: seam-manages persistance (i'm going bananas)
                          andrew.rw.robinson

                          Okay, just tried the latest CVS (had updates to some source and some embedded jar files).

                          Now at least I'm getting some log output, but I can't say it helps:

                          java.lang.IllegalArgumentException: java.beans.IntrospectionException: Method not found: isPersistenceUnitName
                          at org.jboss.seam.Component.initInitializers(Component.java:262)
                          ...
                          at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:30)

                          • 10. Re: seam-manages persistance (i'm going bananas)
                            gavin.king

                            It was renamed to .persistenceUnitJndiName

                            • 11. Re: seam-manages persistance (i'm going bananas)
                              andrew.rw.robinson

                              Sorry I'm causing so much trouble. I still can't get the deployment to work.

                              I am finally seeing the datasource being bound. However, no EJB3's are being found & bound. When I try to hit the web page, I of course get exceptions:

                              java.lang.IllegalStateException: Could not start transaction
                              ...
                              Caused by: javax.naming.NameNotFoundException: comp not bound
                              ...
                              at org.jboss.seam.util.Transactions.getUserTransaction(Transaction.java:29)
                              at org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener.begin(SeamExtendedManagerPersistencePhaseListener.java:53)


                              I've got 3 entity beans (@Entity) and one stateful session bean that is marked with the seam interceptor. Session bean:

                              @Stateful
                              @Name("userAdmin")
                              @Interceptors(SeamInterceptor.class)
                              @Conversational(ifNotBegunOutcome="listUsers")
                              public class UserAdminAction implements UserAdmin
                              {
                               @In(create=true)
                               private EntityManager entityManager;
                              
                               @DataModel(value="adminUserList")
                               private List<User> users;
                              
                               ...
                              
                               @Factory("adminUserList")
                               @Begin(join=true)
                               @SuppressWarnings("unchecked")
                               public void load()
                               {
                               ...// load from the entityManager
                               }


                              My page is just building a datatable on "adminUserList".

                              • 12. Re: seam-manages persistance (i'm going bananas)
                                andrew.rw.robinson

                                Nevermind, I found the issue. Somewhere along the line, I changed my build.xml and the seam.properties was not being deployed into the root of my jar. Dang, what a large waste of time.

                                Thanks for all the help Gavin

                                • 13. Re: seam-manages persistance (i'm going bananas)
                                  emsa

                                   

                                  "gavin.king@jboss.com" wrote:

                                  org.jboss.seam.core.init.managedPersistenceContexts em
                                  em.persistenceUnitJndiName java:/EntityManagerFactories/testDatabase


                                  Means look in "java:/EntityManagerFactories/testDatabase" for the EMF.


                                  Finally got all to run and so decided to upgrade to cvs - got it almost to run but now I get:

                                  11:52:06,258 ERROR [STDERR] Caused by: javax.naming.NameNotFoundException: EntityManagerFactories not bound


                                  both when trying to look up ' java:/EntityManagerFactories/testDatabas' and when running my app.

                                  Did I by any chance miss some new needed configuration?


                                  • 14. Re: seam-manages persistance (i'm going bananas)
                                    gavin.king

                                    Do you have this line in persistence.xml?

                                    <property name="jboss.entity.manager.factory.jndi.name"
                                     value="java:/EntityManagerFactories/testDatabase"/>


                                    1 2 Previous Next