a bunch of tests in the testsuite get the id immediately after persist(). Does this happen if you switch the generator type to AUTO?
Note that the spec does not say anything on that subject
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?
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.
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.