Manage persistent context before flushing?

As answered in your previous question use em. SetFlushMode(FlushType. COMMIT) if you want to avoid any automatic flush before the commit of the JTA transaction (at the end of the EJB method).

Just keep in mind that there will be a flush at commit time.

As answered in your previous question, use em. SetFlushMode(FlushType. COMMIT) if you want to avoid any automatic flush before the commit of the JTA transaction (at the end of the EJB method).

Just keep in mind that there will be a flush at commit time. I would expect that there is nothing flushed into the database, but there is as I can see in the mysql shell. I don't think that the piece of code you're showing illustrates the above question, it's a different question here.

Anyway... before going further, here is what the JPA specification says about clear(): /** * Clear the persistence context, causing all managed * entities to become detached. Changes made to entities that * have not been flushed to the database will not be * persisted. */ public void clear(); So clear() causes all managed entities to become detached, not unmanaged.

In other words, while the spec is a bit cloudy regarding your use case, I don't think that calling clear() is supposed to make the entity passed to persist() in your code snippet a new entity again. I'll test this more extensively tomorrow (even if I think that this use case doesn't make much sense) and will update my answer.

It looks like a hibernate bug. After I switched to eclipselink, It work as expected – coubeatczech Sep 16 '10 at 10:19 @coubeatczech Interesting. I really wonder if this is a bug or a difference in the interpretation of the spec.

Did you create a Jira issue? – Pascal Thivent Sep 16 '10 at 10:23 @coubeatczech Somehow, I'm not convinced that what you "expected" is the right behavior. The JPA spec doesn't define any NEW -> MANAGED -> NEW transition.

And because NEW -> MANAGED -> DETACHED requires to make the entity persistent before to detach it, I think bernate is actually more correct. – Pascal Thivent Sep 16 '10 at 14:54.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions