5 Replies Latest reply on Aug 5, 2005 2:54 PM by dsouza

    Problem with persistence in EJB3 RC1(bug?)

    dsouza

      Hi,

      I ran my test suite on EJB3 RC1 and it failed. I think it might be a bug.

      I have an entity bean with an ID declared as:

       @Id(generate = GeneratorType.SEQUENCE, generator = "MySequence")
       @SequenceGenerator(name = "MySequence", sequenceName = "MY_SEQ")
       public Integer getId() {
       ...
      


      At some point I'm persisting the bean by calling the entity manager's persist() method. After that I need to delete the object from the database but I can't since getId() is now returning null even after the object is persisted.
      The sequence is working and the row is being inserted into the database without any problems.
      In previous versions, immediately after the call to persist(), I'd be able to call getId() on my entity bean and use it for any needed purpose. Is this behaviour correct? Is it a bug?

      I'm using EJB 3 RC1 on JBoss 4.0.3RC1 and Oracle 10g.

      Thanks,
      Denis Souza

        • 1. Re: Problem with persistence in EJB3 RC1(bug?)
          bill.burke

          a bunch of tests in the testsuite get the id immediately after persist(). Does this happen if you switch the generator type to AUTO?

          • 2. Re: Problem with persistence in EJB3 RC1(bug?)
            epbernard

            Note that the spec does not say anything on that subject

            • 3. Re: Problem with persistence in EJB3 RC1(bug?)
              dsouza

              Yes, same thing happens when I switch the generator type to AUTO.

              True that the spec doesn't say anything, but it does makes sense to be able to obtain the id from a recently persisted entity. Is there another way to do this?

              • 4. Re: Problem with persistence in EJB3 RC1(bug?)
                epbernard

                if you flush.

                But anyway, Hibernate should not act like that, and as said by bill, we have some unit tests that cover it. Can your reproduce it in a minimal test case. If so post it to JIRA.

                • 5. Re: Problem with persistence in EJB3 RC1(bug?)
                  dsouza

                  I started to write a simple test case in a separate project to send to JIRA and in the process I found what was going on.
                  Fist let me explain a little bit more about how my project is set up.

                  In order to do some logging and other stuff important to my app, I never use the EntityManager directly. Instead I have a stateless bean that wraps the entity manager's funcionality and does whatever else is needed.
                  So even in my test suites, I use this bean to access the database. The bean was declared only having a remote interface. I guess that due to some detatchment issue it wasn't updating the id after persisting. Once I declared a local interface for it, everything started working again.

                  I don't know if the behavior is correct, but at least now there's a way to reproduce it. If you have trouble reproducing it I can still send you the test I created for it.

                  Thanks for your help.