From: Gavin_King/Cirrus%<CI...@ci...> - 2002-03-04 03:08:27
|
> It seems to me that the HILo Key generator only works if Hibernate > manages the jdbc connections, because it wants to open a separate > connection. Why is that needed? Also the comments in the code say that > it wont work with application server datasources. Why is that the case? Yeah, sorry the code comment is wrong. It *should* read: "only works when using DriverManagerConnectionProvider" It doesn't work if you supply a connection + it doesn't work with a datasource. The reason for this is that we would need HiLoGenerator to be notified of a transaction rollback in the (rare) event that the transaction got rolled back on the transaction we grabbed the new hi value. Also, other sessions would be blocked from using the generator until we knew the outcome of that transaction. All this doesn't fit the overall architecture very well. I actually didn't remember this earlier (even though I knew it the last time I implemented a hi/lo generator) and earlier versions were using the same connection as the session...... The solution is to have an alternate implementation of HiLoGenerator that uses a stateless session bean with (TX_REQUIRES_NEW) to grab and increment the hi value. Daniel has implemented this and will release it when hes ready, i guess..... > I think uuids are a bit ugly, and hibernate doesnt seem to support > database native key generation, so I dont know whats the best way to > generate pks right now. My advice is: implement your own id generator class (possibly as a stop-gap measure) using whatever makes sense for your environment. Its _really_ easy to implement IDGenerator .... like *one* method or something..... there will certainly be more options in the next version. sorry about this situation it was my dumb mistake.... |