1 2 Previous Next 18 Replies Latest reply on Apr 11, 2007 9:17 AM by Lindsay H

    looking for non-EJB SEAM example...

    Lindsay H Newbie

      Hi there,

      I'm using SEAM with old Hibernate3 code/mappings that we have and I was under the impression from the reference guide that this meant I couldn't use the EJB3 part of SEAM.

      So I'm looking for any example that uses plain old javabeans? There's a hibernate example in the jboss-seam project, but it uses the @Entity annotation for one of it's beans - and I'm slightly confused by this. It also uses the microcontainer. My project doesn't.

      I'd really like to get started on SEAM without having to get familiar with EJB3 - if at all possible. There's enough new stuff there already!


        • 1. Re: looking for non-EJB SEAM example...
          Christian Bauer Master

          Take the Hibernate example and remove the annotations on the entity if they bother you. Move the mapping into a Hibernate XML file. The example uses the microcontainer, this doesn't mean it is using EJBs.

          • 2. Re: looking for non-EJB SEAM example...
            Sander Mak Newbie

            I have a question that's slightly related... What if I want to use an existing EntityManager that's defined in an SE setting? The JPA example in the distribution seems to be closest to what I want, but my persistence.xml already contains all the information needed to connect to a database. I would like to avoid the microcontainer to manage the connection and datasource, is this possible at all? JTA is not necessary, transaction-type is defined as RESOURCE-LOCAL...


            • 3. Re: looking for non-EJB SEAM example...
              Christian Bauer Master

              Let Seam start the persistence unit, this will scan for META-INF/persistence.xml and deploy the "wiki" persistence unit if you put it in components.xml:

               <core:managed-persistence-context name="entityManager"
               <core:entity-manager-factory name="wikiEntityManagerFactory" persistence-unit-name="wiki"/>

              Now use @In entityManager to get a Seam-managed persistence context that is automatically scoped to the conversation. You also want to use the TransactionalSeamPhaseListener in your faces-config.xml with that.

              • 4. Re: looking for non-EJB SEAM example...
                Christian Bauer Master

                Oh, that still needs JTA. Really, Seam does not work well without JTA - and why should it: JTA is the standard transaction API in Java. So you need at least a JTA provider, which is what the microcontainer gives you.

                • 5. Re: looking for non-EJB SEAM example...
                  Sander Mak Newbie

                  Okay, I'm rewriting the JPA example towards my intended use. Only, Hibernate is giving me this exception:

                  javax.persistence.PersistenceException: org.hibernate.HibernateException: The chosen transaction strategy requires access to the JTA TransactionManager

                  Which seems natural, since there is no reference to a JTA provider in my persistence.xml:

                  <?xml version="1.0" ?>
                  <persistence 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" version="1.0">
                   <persistence-unit name="blog" transaction-type="JTA">
                   <property name="hibernate.archive.autodetection" value=""/>
                   <property name="hibernate.show_sql" value="true"/>
                   <property name="hibernate.format_sql" value="true"/>
                   <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
                   <property name="hibernate.connection.url" value="jdbc:hsqldb:hsql://localhost/blogjpa"/>
                   <property name="hibernate.connection.username" value="sa"/>
                   <property name="hibernate.c3p0.min_size" value="5"/>
                   <property name="hibernate.c3p0.max_size" value="20"/>
                   <property name="hibernate.c3p0.timeout" value="300"/>
                   <property name="hibernate.c3p0.max_statements" value="50"/>
                   <property name="hibernate.c3p0.idle_test_period" value="3000"/>
                   <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
                   <property name="hibernate.hbm2ddl.auto" value="create"/>

                  In the persistence.xml of the JPA example, this line is added:


                  However, this is the datasource I'm not defining through the microcontainer... how can I link to the JTA implementation without having to reference such a datasource? Judging from the schema definition for persistence.xml there is no such possibility?

                  • 6. Re: looking for non-EJB SEAM example...
                    Christian Bauer Master

                    You need to reference a JTA-managed datasource in persistence.xml, there is no way around it. Install a JTA provider, easiest is the JBoss Microcontainer which out-of-the-box provides JTA, JNDI, and JCA services. You can not use a resource local database configuration with JPA and Seam.

                    • 7. Re: looking for non-EJB SEAM example...
                      Christian Bauer Master

                      In case this isn't clear: "Just JTA without a datasource" doesn't work. The whole point is that the JTA transaction manager handles your datasource.

                      • 8. Re: looking for non-EJB SEAM example...
                        Sander Mak Newbie

                        Ok, thanks for clearing that up! I was just trying to reuse as much as possible from the 'legacy' code, guess I'll have to do some porting. Thanks for your time!

                        • 9. Re: looking for non-EJB SEAM example...
                          Christian Bauer Master

                          Actually the whole picture is:

                          - Seam should only require JTA if you use TransactionalSeamPhaseListener because then Seam will call JTA to begin and end transactions

                          - Seam will start whatever EntityManagerFactory you configure in components.xml for you

                          - The issue is that you also want Seam-managed persistence contexts, so you let Seam have that EMF and open and close EntityManagers for you. This doesn't make much sense if you do not also let Seam handle transactions for you.

                          So conclusion: Seam-managed persistence contexts require a JTA runtime because the transaction handler is using the standard JTA interfaces.

                          • 10. Re: looking for non-EJB SEAM example...
                            Christian Bauer Master

                            And finally back to topic of this thread: All of this has nothing to do with EJBs, Seam works fine without an EJB container.

                            • 11. Re: looking for non-EJB SEAM example...
                              Sander Mak Newbie

                              Ok, so it's working now using the microcontainer. Now, how can I inspect the database? In my 'stand-alone' setting I could connect the HSQLDBManager using the connection-string I provided myself in persistence.xml. Can I still do something similar now that my database is managed by the microcontainer?

                              • 12. Re: looking for non-EJB SEAM example...
                                Christian Bauer Master

                                Your database isn't managed by the microcontainer... The microcontainer is just running a connection pool service for you. So you connect to your database the same way the microcontainer is connecting to it.

                                • 13. Re: looking for non-EJB SEAM example...
                                  Sander Mak Newbie

                                  Man, all these layers upon other layers and their configuration... it's a bit overwhelming. Anyway, the jboss-beans.xml (the name of this file implied to me that the db connection was managed by the microcontainer by the way) is an adaptation of the one in the JPA example:

                                  <?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"
                                   <bean name="Naming" class="org.jnp.server.SingletonNamingServer"/>
                                   <bean name="TransactionManagerFactory"
                                   <bean name="TransactionManager" class="java.lang.Object">
                                   <constructor factoryMethod="getTransactionManager">
                                   <factory bean="TransactionManagerFactory"/>
                                   <bean name="bookingDatasourceFactory"
                                   <property name="driverClass">org.hsqldb.jdbcDriver</property>
                                   <property name="connectionUrl">jdbc:hsqldb:testing</property>
                                   <property name="userName">sa</property>
                                   <property name="jndiName">java:/DefaultDS</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"/>
                                   <bean name="bookingDatasource" class="java.lang.Object">
                                   <constructor factoryMethod="getDataSource">
                                   <factory bean="bookingDatasourceFactory"/>

                                  I guess this creates the in-memory variant of the HSQL database? So far I've only connected to file-based ones. Using the string jdbc:hsqldb:testing in HSQLDBManager does connect, but shows an empty DB (though the schema export allegedly succeeded). Furthermore, changing testing to any arbitrary name leads to a succesful connection, that's suspicious...

                                  • 14. Re: looking for non-EJB SEAM example...
                                    Christian Bauer Master

                                    Yes, this is an in-process database, you can't connect to it with a TCP-based tool (it doesn't listen on any port). What you are seeing is just that several in-process databases are started for every process that wants to "connect". Use a standalone HSQL DB configuration.

                                    1 2 Previous Next