Anders Bolager wrote:
> Santiago Gala wrote:
>
> <snip>
>
> >
> > What I'm doing is:
> >
> > Create a findGreatestId() method for each CMP bean. the where clause would be
> > something like:
> >
> > WHERE id = (SELECT max(id) FROM table)
> >
> > Call it inside the ejbCreate method to get the biggest used id, increment it and
> > assign it before returning. Warning: it will raise and exception, that must be
> > caught, if the table is empty. In this case, set id to 1.
> >
> > It should work well, it is completely portable and it uses all the connection
> > pooling and similar characteristics in Jonas.
> >
> > It is not very elegant, but we have seen no problems using it. If you require
> > permanent unique ids, and you are removing objects, it is not for you, as the same
> > id can be reused if the last object is created and then removed.
>
> Are you sure this is thread safe? What if two threads tries to create a
> new bean, and
> the server is switching out one for the other while the first sent the
> sql to get the
> current max, while not yet incremented the number.
>
> In a busy environment, these things happen every so often. On a perl
> system a friend
> was working on, new users got someone elses account number about twice a
> week.
>
It should be as the whole create call is executed in a transaction (spec 1.1). The
server takes care of this
>
> <snip>
>
> Regards,
> Anders Bolager
> ----
> To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the body of the message "unsubscribe jonas-users".
> For general help, send email to [EMAIL PROTECTED] and
> include in the body of the message "help".
----
To unsubscribe, send email to [EMAIL PROTECTED] and
include in the body of the message "unsubscribe jonas-users".
For general help, send email to [EMAIL PROTECTED] and
include in the body of the message "help".