[jboss-user] [JBoss Seam] - Re: persist() / remove() at end of long running conversation

mgombocz do-not-reply at jboss.com
Thu Feb 22 13:15:32 EST 2007


Hi,
I have similar problems, so I did further tests based on

- JBoss AS 4.0.5.GA
- Seam CVS nightly build of 02/18/2007 (based on 1.1.6.GA)
- Hibernate as (preconfigured) JPA provider

My initial situation is the same like the one of m_hess (using SMPC and flushMode=FlushModeType.MANUAL):
anonymous wrote : Hi, 
  | 
  | I´m experimenting with Seam Managed long running atomic conversations right now. I succesfully managed to have changes made to existing entities get flushed when the @End method is called. This works fine so far and is conform to my understanding of a Seam Managed Transaction using @Begin and @End Annotations. 
  | 
  | My next step was to create a new entity during that conversation. To attach the new instance to the entityManager I´m using persist() (side note: tried merge() as well, no difference). What puzzles me, is that immediately when em.persist(myNewInstance) is called, an insert is happening (used the debugger to confirm this). 
  | 
  | I tested some more, and so far I can say, that it´s only the insert that is happening at the time persist() is called. When I have also made changes to the already existing entities in the same conversation, they are still correctly updated at the end of the conversation, not before. 

I tested 2 scenarios:

1) Using @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) on relevant methods
The Entity's @Id field is annotated with @GeneratedValue (i.e. by default: strategy=AUTO).
After calling persist() no immediate SQL INSERTs are performed (-->correct).

BUT, by calling the method which calls flush() it causes an exception:
org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.Long, got class org.hibernate.action.DelayedPostInsertIdentifier

2) Using @GeneratedValue (strategy = GenerationType.SEQUENCE, ...) on Entity objects
By using Sequences SQL INSERTs will performed after calling flush(). No @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) annotation is required (-->very good).

BUT, not all RDBMS systems, like e.g. MySQL, support sequences. :-(


re. 1) Has anybody made the same experience or do I something wrong?
re. 2) Are there other ways that are supported by all RDBMS or at least MySQL?

Thanks!

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4020737#4020737

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4020737




More information about the jboss-user mailing list