11 Replies Latest reply on Oct 11, 2011 3:47 PM by amitajmani1

    JBoss5.1.0 + JPA = Object not persists

    amitajmani1

      here is my persistent.xml:

      <persistence-unit name="jpa_ora" transaction-type="JTA">

        <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <jta-data-source>java:OraDS</jta-data-source>

        <mapping-file>META-INF/orm.xml</mapping-file>

        <class>ca.teranet.rts.model.User</class>

        <class>ca.teranet.rts.dao.UserSession</class>

        <exclude-unlisted-classes>true</exclude-unlisted-classes>

        <properties>

         <property name="hibernate.show_sql" value="true" />

         <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />

         <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />

            </properties>

      </persistence-unit>

       

      and i am using TransactionManagement.Container in my Stateless EJB. I have put the hibernate-jpa-2.0-final.jar in server/default/lib folder.

       

      The problem is :

      Whenever i invoke a method to persist an object, sometimes it works well and save it into DB and sometimes it wont, just increases the hibernate_sequence value and and comes out silently without even throwing an exception but does not fire an insert query .

       

      But when i run the same application over JBoss6.0 it works perfectly.

       

      Any clue on this ........

        • 1. Re: JBoss5.1.0 + JPA = Object not persists
          wdfink

          Why you put hibernate-jpa-2.0 jar into the lib directory. The JBoss supports hibernate and jpa (maybe not 2.0) and it might conflict with it.

          Do you must use jpa2.0??

           

          Work sometimes sounds to me like a transaction rollback ... do you see any in the logfiles?

           

          Why and what do you use instead of 6.0 when it works with it?

          • 2. Re: JBoss5.1.0 + JPA = Object not persists
            amitajmani1

            Why you put hibernate-jpa-2.0 jar into the lib directory. The JBoss supports hibernate and jpa (maybe not 2.0) and it might conflict with it.

            Do you must use jpa2.0??

             

            • > Initially i thought that JPA annotations are only supported in Jpa 2.0 hence i put that jar in my lib folder. now i have removed it and annotations works..

             

            Work sometimes sounds to me like a transaction rollback ... do you see any in the logfiles?

             

            • > No i didn't get any rollback exceptions......

             

            Why and what do you use instead of 6.0 when it works with it?

             

            • > we have planned to setup JBoss5.1.0 enterprise edition on production server since Jboss does not give production support on version 6.0 or later...
            • 3. Re: JBoss5.1.0 + JPA = Object not persists
              wdfink

              I have a running implementation with JBoss 5.1.1 EAP (supported) and also a 5.1 (community) without changes to hibernate running.

              A standard JPA entity with annotations works without problems.

               

              You might set 'org.hibernate' to TRACE to see what happen in case of lost 'persist'

              1 of 1 people found this helpful
              • 4. Re: JBoss5.1.0 + JPA = Object not persists
                amitajmani1

                After setting the org.hibernate to TRACE in logger i found this :

                 

                2011-10-04 18:10:23,559 TRACE [org.hibernate.jdbc.JDBCContext] (http-127.0.0.1-8080-1) TransactionFactory reported no active transaction; Synchronization not registered

                 

                how to fix this .......i have already set  @TransactionManagement(TransactionManagementType.CONTAINER) on my stateless ejb.

                 

                • 5. Re: JBoss5.1.0 + JPA = Object not persists
                  amitajmani1

                  One thing i have noticed that the moment i boot my server up and deploy the application , the first transaction completed successfully, and then after wards it gives messages like  "TransactionFactory reported no active transaction; Synchronization not registered".

                   

                  any idea where i am making mistake..... or how to use CMT over Stateless EJB3.0 with JBOSS 5.1.0GA.......?

                  • 6. Re: JBoss5.1.0 + JPA = Object not persists
                    wdfink

                    How do you annotate your SLSB?

                    Where do you add @TransactionAttribute? At class or method level and what do you use REQUIRED, SUPPORTS?

                    Do you use only one SLSB or a chain of it?

                    • 7. Re: JBoss5.1.0 + JPA = Object not persists
                      amitajmani1

                      How do you annotate your SLSB?

                       

                      Answer :

                      here is my SLSB :

                       

                       

                       

                      public interface UserService {

                       

                         public List<User> getRegisteredUsers();

                       

                       

                       

                         public void registerUser(User user);

                       

                      }

                       

                       

                       

                       

                       

                       

                       

                       

                       

                       

                       

                       

                      // this is a simple POJO class containing business logic

                       

                      private UserServiceCoreImpl coreService;

                       

                      public UserServiceImpl(){

                       

                           coreService = new UserServiceCoreImpl();

                       

                      }

                       

                      publicList<User> getRegisteredUsers(){

                           coreService.getRegisteredUsers();

                      ....

                      }

                       

                         // performs a database INSERT operation

                         public void registerUser(User user){

                           coreService.registerUser(user);

                       

                      }

                       

                       

                      }

                       

                       

                       

                      Where do you add @TransactionAttribute? At class or method level and what do you use REQUIRED, SUPPORTS?

                       

                      Answer : At the class level as you can see from above code snippet.

                       

                      We are using a single SLSB which invokes a POJO class containing the business logic and which also performs the database operation.

                       

                       

                       

                       

                      public class UserServiceImpl implements UserService {

                       

                      @Stateless

                      @TransactionManagement(TransactionManagementType.CONTAINER)

                       

                       

                       

                      @Remote

                      • 8. Re: JBoss5.1.0 + JPA = Object not persists
                        wdfink

                        your post it a bit messed up, isn't it

                        but as I can see there is no '@TransactionAttribute(TransactionAttributeType.REQUIRED)' annotation neither on class nor on method-level.

                        It should be the default but I don't see your complete code.

                        You might active logging on 'com.arjuna.ats' to see the Tx stuff.

                        • 9. Re: JBoss5.1.0 + JPA = Object not persists
                          amitajmani1

                          Actually i tried to answer line by line....

                          ok , here my code

                          @Remote

                          public interface UserService {

                             public List<User> getRegisteredUsers();   public void registerUser(User user);

                           

                          @Stateless

                          @TransactionManagement(TransactionManagementType.CONTAINER)

                          public class UserServiceImpl implements UserService {

                           

                               private UserServiceCoreImpl userService;

                           

                          public UserServiceImpl(){

                               userService = new UserServiceCoreImpl();

                          }   

                          public List<User> getRegisteredUsers(){

                               return userService.getRegisteredUsers();        

                          }

                          public void registerUser(User user){

                               userService.registerUser(user);

                          }

                           

                          }

                           

                          public class UserServiceCoreImpl implements UserService{

                               private GenericDao dao;

                           

                          public UserServiceCoreImpl(){

                             dao = new GenericDaoImpl();

                          }

                          public GenericDao getDao(){

                               return dao;

                          }

                           

                          public void registerUser(User user){

                                    getDao().persist(user);

                          }

                          ...........................

                          .............................

                          }

                           

                           

                          }

                          • 10. Re: JBoss5.1.0 + JPA = Object not persists
                            amitajmani1

                            I tried annotation @TransactionAttribute(TransactionAttributeType.REQUIRED) at method level, but no success. i have also attached the logs .....

                             

                            may be the attached logs help you to point out the problem area.......

                            • 11. Re: JBoss5.1.0 + JPA = Object not persists
                              amitajmani1

                              Hi,

                               

                              I found the solution .

                              just need to put these properties in the persistence.xml file and it all works fine..

                               

                              <code>

                              <persistence-unit name="jdbcService" transaction-type="JTA">

                              ........

                              <property name="jboss.entity.manager.jndi.name" value="java:/jdbcService"></property>

                               

                               

                               

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

                              </code>

                               

                              thanks for all your kind support.....:)

                               

                              Amit