6 Replies Latest reply on Mar 17, 2009 2:01 PM by Oguzhan YALCIN

    Newbie, Seam & EJBTransactionRolledbackException

    peter irmstadt Newbie

      Hi!


      Seam is quite new for me. I bought the book JBoss Seam - Simplicity and power beyond Java EE and tried to reproduce the first example using JBoss AS 4.2.3.GA and Seam 2.1.1 GA, Eclipse and the JBoss Tools.


      These are the steps I made:


      1) Created a new project mySeamTest using JBoss Tools
      - EAR
      - Bound to existing MySQL Database, ping was successful
      - Chose the packages myseamtest.entity and myseamtest.session


      2) The JBoss Tools created three subprojects (mySeamTest-ear, mySeamTest-ejb, mySeamTest)


      3) I created a new Java class under mySeamTest-ejb \ ejbModule
      \ myseamtest.entity \


      -- Person.Java --



      @Entity
      @Name("person")
      public class Person implements Serializable {
           private static final long serialVersionUID = 1L;
           
           private long id;
           private String name;
           
           @Id @GeneratedValue
           public long getId() { return id;}
           public void setId(long id) {this.id = id;}
           
           public String getName() {return name;}
           public void setName(String name) {this.name = name;}
      }




      4) Created two new files under  mySeamTest-ejb \
      ejbModule \ myseamtest.entity


      -- Manager.java --



      @Local
      public interface Manager 
      {
           public String sayHello ();
      }





      -- ManagerAction.java --



      @Stateless
      @Name("manager")
      public class ManagerAction implements Manager 
      {
           @In @Out
           private Person person;
           
           @Out
           private List <Person> fans;
           
           @PersistenceContext
           private EntityManager em;
           
      
           public String sayHello() {
                em.persist(person);
                person = new Person();
                fans = em.createQuery("select p from Person p").getResultList();
                return null;
           }
      }
      



      5) Created the related page


      -- (Important part of) test.xhtml --



      <h:form>
              Please enter your name:<br/>
              <h:inputText value="#{person.name}" size="15" />
              <br/>
              <h:commandButton action="#{manager.sayHello}" value="Say Hello" type="submit" />
              </h:form>
              <h:dataTable value="#{fans}" var="fan">
              <h:column>
              <h:outputText value="#{fan.name}" />
              </h:column>
              </h:dataTable>



      When I am going to deploy that project the page is loaded correctly and no error is shown in the console. But when I try to type something in the textbox and then click on the submit button, the following exception(s) appear: http://nopaste.info/17240bf0d7.html


      Do you have any idea what I can try to solve that problem?


      Thank you so much in advance!

        • 1. Re: Newbie, Seam & EJBTransactionRolledbackException
          Adrien Orsier Newbie

          Hmm I understand the exception but don't really know why it's happenning.


          By Annotating your Entity Person with @Name, you create a Component with this class. What is hapenning is that the entityManager is trying to persist this component, and not the Entity that the component relies on.
          First, try to declare your entity manager like this:



          @In
          EntityManager entityManager




          instead of your


          @PersistenceContext
          private EntityManager em;



          Not quite sure it could work anyway, but it's always better to use the Seam Managed persistence context.
          Tell me if it didn't work :)

          • 2. Re: Newbie, Seam & EJBTransactionRolledbackException
            Ralf H. Newbie

            Hum,


            maybe the problem is in your code.


            it says:


            @In @Out
            private Person person;
            



            and in the method 'sayhello' you say:


            em.persist(person);
            



            @In says, that the Person is injected, but from where?
            Maybe there is an NPE. You should check, whether person is not defined in your runtime.






            • 3. Re: Newbie, Seam & EJBTransactionRolledbackException
              Stuart Douglas Master

              This is kind of weird. You person entity seems to be a javassist enhanced, which should not happen. When persist is called the actual class is myseamtest.session.Person_$$_javassist_1  which is not mapped, so hibernate throws an exception. Entity beans should never be ehanced, which is why they do not have access to seam interceptor functionality.


              This looks like it may be a seam bug, what version are you using?


              Also what happens if you put an @Table annotation on your entitiy bean?


              • 4. Re: Newbie, Seam & EJBTransactionRolledbackException
                Oguzhan YALCIN Newbie

                I got the same error and when I write the entity classes to the persistence.xml everything works fine...


                <class>myseamtest.entity.person</class>


                • 5. Re: Newbie, Seam & EJBTransactionRolledbackException
                  peter irmstadt Newbie

                  Thank you for your answers!



                  Ralf H. wrote on Mar 16, 2009 12:02:


                  @In says, that the Person is injected, but from where?



                  It is injected (as far as I understand Seam bijection) from that part of the page.xhtml:


                  <h:inputText value="#{person.name}" size="15" />




                  Stuart Douglas wrote on Mar 16, 2009 12:23:


                  This is kind of weird. You person entity seems to be a javassist enhanced, which should not happen. When persist is called the actual class is myseamtest.session.Person_$$_javassist_1  which is not mapped, so hibernate throws an exception. Entity beans should never be ehanced, which is why they do not have access to seam interceptor functionality.

                  This looks like it may be a seam bug, what version are you using?

                  Also what happens if you put an @Table annotation on your entitiy bean?



                  I already tried to use @Table, but that doesn't change anything. I am using version 2.1.1.GA of Seam.



                  Oguzhan YALCIN wrote on Mar 16, 2009 14:42:


                  I got the same error and when I write the entity classes to the persistence.xml everything works fine...

                  <class>myseamtest.entity.person</class>





                  I do not have a persistence.xml at all. It is not created and the settings are stored in hibernate-console.properties. What is that file about?



                  Adrien Orsier wrote on Mar 16, 2009 11:52:


                  Hmm I understand the exception but don't really know why it's happenning.

                  By Annotating your Entity Person with @Name, you create a Component with this class. What is hapenning is that the entityManager is trying to persist this component, and not the Entity that the component relies on.
                  First, try to declare your entity manager like this:


                  @In
                  EntityManager entityManager




                  instead of your

                  @PersistenceContext
                  private EntityManager em;




                  I tried that as well. No change at all.



                  Any other ideas?


                  Thank you and regards,


                  Peter

                  • 6. Re: Newbie, Seam & EJBTransactionRolledbackException
                    Oguzhan YALCIN Newbie

                    There must be a persistence.xml under your myseamtest-EJB project under the META-INF directory or somewhere else. Try to search from your windows explorer starting from your project folder. hibernate-console and persistence.xml are not the same. I have this error after running seam generate entities when i put the <class> tags everything works perfect.