Wei-ju Wu wrote:
> Could you please explain me the difference between using an
> AutoNumberBean and just doing a
>
> SELECT MAX(<id>) FROM <tablename> please ?
>
With an auto-number bean you can define it to be in its own transaction
('RequiresNew') and force a high isolation level (or use 'select ... for
update' syntex) so that the row in question is locked but not for any
longer than it takes to get the value and increment it.
With the select max solution, you're either not locking the rows (which
means that it's possible for two concurrent inserts to try to use the
same PK value - bad) or your locking the entire table, causing all
concurrent inserts to be serialized (which might happen anyway,
depending on the database, that tables indexing style on its primary
key, and probably a lot of other things)
> I think these both approaches are similar and the above
> one is the one I use. Is there a performance disadvantage
> using a select max or can the database optimize the
> access by using the index ? Or could there be conflicts
> with the CMP ?
The main issue is the concurrency.
-danch
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user