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9sPz9iPz8sPz8/eT8rPz/etz9i Pz8/PystP3c/Pz9rP3gfPz8/woo/dT/elj9ecj09PQ0KCT4NCgkNCgkNCgkNCgkNCgkNCgktLS0t LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tDQoJVGhp cyBTRi5uZXQgZW1haWwgc3BvbnNvcmVkIGJ5OiBFbnRlcnByaXNlIExpbnV4IEZvcnVtIENvbmZl cmVuY2UgJiBFeHBvDQoJVGhlIEV2ZW50IEZvciBMaW51eCBEYXRhY2VudGVyIFNvbHV0aW9ucyAm IFN0cmF0ZWdpZXMgaW4gVGhlIEVudGVycHJpc2UNCglMaW51eCBpbiB0aGUgQm9hcmRyb29tOyBp biB0aGUgRnJvbnQgT2ZmaWNlOyAmIGluIHRoZSBTZXJ2ZXIgUm9vbQ0KCWh0dHA6Ly93d3cuZW50 ZXJwcmlzZWxpbnV4Zm9ydW0uY29tDQoJX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX18NCglTcHJpbmdmcmFtZXdvcmstZGV2ZWxvcGVyIG1haWxpbmcgbGlzdA0K CVNwcmluZ2ZyYW1ld29yay1kZXZlbG9wZXJAbGlzdHMuc291cmNlZm9yZ2UubmV0DQoJaHR0cHM6 Ly9saXN0cy5zb3VyY2Vmb3JnZS5uZXQvbGlzdHMvbGlzdGluZm8vc3ByaW5nZnJhbWV3b3JrLWRl dmVsb3Blcg0KCQ0KDQo= |
|
From: <jue...@we...> - 2003-10-20 17:49:36
|
Thomas, Trevor, > Does Hibernate use a different ID strategy for different databases? I = think what is implemented in the Petclinic is a strategy that would work the = same across different databses as long as there is a MaxValueIncrementer = implementation. I intend to configure Hibernate to use "identity" for all databases. = Setting the correct Hibernate dialect will lead to "auto_increment" on = MySQL and "identity" on HSQL then. In terms of the data model, this = simply means dropping the sequence tables and defining the id columns as = "auto_increment" respectively "identity" in the DDL scripts. Sure, MaxValueIncrementer adopts a very generic approach that will work = on any database, even if it doesn't support such a thing like identity = columns. The disadvantage is that the mechanism is normally not native = to the database and thus somewhat tied to the application. > If we change the Petclinic JDBC implementation to use identity = columns, then we need to figure out how to run the insert and subsequent query to = retrieve the id using the same connection whether we are in a transaction or not. This is very similar with MySQL and HSQL: You simply run the insert = without specifying a value for the id field, and query "select = last_insert_id()" respectively "call identity()" afterwards (I've looked = up the latter in Hibernate's MySQLDialect and HSQLDialect = implementations). Petclinic already uses MySQLJdbcClinic and = HSQLJdbcClinic subclasses; it should be easy to encapsulate the = id-fetching query there. Of course, the range of possible Petclinic JDBC implementations will = then be bound to identity-supporting databases. According to the = Hibernate docs, those are "DB2, MySQL, MS SQL Server, Sybase and = HypersonicSQL". Oracle is notably absent; I think we can live with = Petclinic not running on Oracle, if we can allow for a dynamic switch = between JDBC and Hibernate on both MySQL and HSQL that way! >>auto-increment just allows to read in the actual id afterwards >This is not reliable for concurrent inserts (which is why I generally = use sequences. For the sample this should be sufficient though. According to what I found out about MySQL, "last_insert_id" returns the = last used id on the same connection and is thus transactionally safe. = Don't know about HSQL, but I frankly don't mind for sample purposes. Juergen |
|
From: <tri...@tr...> - 2003-10-20 18:52:15
|
Juergen, > According to what I found out about MySQL, "last_insert_id" returns the last > used id on the same connection and is thus transactionally safe. Don't know > about HSQL, but I frankly don't mind for sample purposes. > HSQL has IDENTITY() which returns the last identity value for the connection - so the functionality is basically the same. We just have to make sure that we use the same connection - an sqlUpdate followed by an sqlQuery might not gurantee this. I have been thinking about creating a datasource that makes the same conection available for a series of database interactions (with supressClose turned on) - like a temporary SingleConnectionDataSource created from a pooled DataSource. What do you think of a MultipleUseConnectionDataSource that gets a DataSource passed in the constructor. This MultipleUseConnectionDataSource could then be passed in to several sqlUpdate or sqlQuery objects and deflect any attempts to close it during this sequence of database interaction. Finally we would call destroy() on the MultipleUseConnectionDataSource causing the connection to be returned to the pool. Thomas |
|
From: Colin S. <col...@ex...> - 2003-10-20 20:02:24
|
jürgen höller [werk3AT] wrote: >Thomas, Trevor, > >>oes Hibernate use a different ID strategy for different databases? I think >> >> >what is implemented in the Petclinic is a strategy that would work the same >across different databses as long as there is a MaxValueIncrementer implementation. > >I intend to configure Hibernate to use "identity" for all databases. Setting the correct Hibernate dialect will lead to "auto_increment" on MySQL and "identity" on HSQL then. In terms of the data model, this simply means dropping the sequence tables and defining the id columns as "auto_increment" respectively "identity" in the DDL scripts. > >Sure, MaxValueIncrementer adopts a very generic approach that will work on any database, even if it doesn't support such a thing like identity columns. The disadvantage is that the mechanism is normally not native to the database and thus somewhat tied to the application. > >>f we change the Petclinic JDBC implementation to use identity columns, then we >> >> >need to figure out how to run the insert and subsequent query to retrieve the id >using the same connection whether we are in a transaction or not. > >This is very similar with MySQL and HSQL: You simply run the insert without specifying a value for the id field, and query "select last_insert_id()" respectively "call identity()" afterwards (I've looked up the latter in Hibernate's MySQLDialect and HSQLDialect implementations). Petclinic already uses MySQLJdbcClinic and HSQLJdbcClinic subclasses; it should be easy to encapsulate the id-fetching query there. > >Of course, the range of possible Petclinic JDBC implementations will then be bound to identity-supporting databases. According to the Hibernate docs, those are "DB2, MySQL, MS SQL Server, Sybase and HypersonicSQL". Oracle is notably absent; I think we can live with Petclinic not running on Oracle, if we can allow for a dynamic switch between JDBC and Hibernate on both MySQL and HSQL that way! > > I guess you are trying to make the exact same thing run under both Hibernate and JDBC, but if you are willing to say the Oracle DB only works with the Hibernate version (and handle the DDL separately too), then you can easily do that by just using 'native' as the Hibernate type... |
|
From: Ken K. <kk...@kk...> - 2003-10-20 22:03:18
|
It might be most useful to implement one of the 2 databases as is using=20 the MaxValueIncrementer while implementing the other using Hibernate to=20 preserve both types of examples. Ken j=FCrgen h=F6ller [werk3AT] wrote: >Thomas, Trevor, > > =20 > >>Does Hibernate use a different ID strategy for different databases? I = think >> =20 >> >what is implemented in the Petclinic is a strategy that would work the s= ame >across different databses as long as there is a MaxValueIncrementer impl= ementation. > >I intend to configure Hibernate to use "identity" for all databases. Set= ting the correct Hibernate dialect will lead to "auto_increment" on MySQL= and "identity" on HSQL then. In terms of the data model, this simply mea= ns dropping the sequence tables and defining the id columns as "auto_incr= ement" respectively "identity" in the DDL scripts. > >Sure, MaxValueIncrementer adopts a very generic approach that will work = on any database, even if it doesn't support such a thing like identity co= lumns. The disadvantage is that the mechanism is normally not native to t= he database and thus somewhat tied to the application. > > =20 > >>If we change the Petclinic JDBC implementation to use identity columns,= then we >> =20 >> >need to figure out how to run the insert and subsequent query to retriev= e the id >using the same connection whether we are in a transaction or not. > >This is very similar with MySQL and HSQL: You simply run the insert with= out specifying a value for the id field, and query "select last_insert_id= ()" respectively "call identity()" afterwards (I've looked up the latter = in Hibernate's MySQLDialect and HSQLDialect implementations). Petclinic a= lready uses MySQLJdbcClinic and HSQLJdbcClinic subclasses; it should be e= asy to encapsulate the id-fetching query there. > >Of course, the range of possible Petclinic JDBC implementations will the= n be bound to identity-supporting databases. According to the Hibernate d= ocs, those are "DB2, MySQL, MS SQL Server, Sybase and HypersonicSQL". Ora= cle is notably absent; I think we can live with Petclinic not running on = Oracle, if we can allow for a dynamic switch between JDBC and Hibernate o= n both MySQL and HSQL that way! > > =20 > >>>auto-increment just allows to read in the actual id afterwards >>> =20 >>> >>This is not reliable for concurrent inserts (which is why I generally u= se sequences. For the sample this should be sufficient though. >> =20 >> > >According to what I found out about MySQL, "last_insert_id" returns the = last used id on the same connection and is thus transactionally safe. Don= 't know about HSQL, but I frankly don't mind for sample purposes. > >Juergen > > >------------------------------------------------------- >This SF.net email sponsored by: Enterprise Linux Forum Conference & Expo >The Event For Linux Datacenter Solutions & Strategies in The Enterprise=20 >Linux in the Boardroom; in the Front Office; & in the Server Room=20 >http://www.enterpriselinuxforum.com >_______________________________________________ >Springframework-developer mailing list >Spr...@li... >https://lists.sourceforge.net/lists/listinfo/springframework-developer > > > =20 > |
|
From: <jue...@we...> - 2003-10-20 22:28:16
|
VGhvbWFzLA0KIA0KV2UgZG9uJ3QgbmVlZCB0byBhZGRyZXNzI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Zyb250IE9mZmljZTsgJiBpbiB0aGUgU2VydmVyIFJvb20NCglodHRwOi8vd3d3LmVudGVycHJp c2VsaW51eGZvcnVtLmNvbQ0KCV9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fDQoJU3ByaW5nZnJhbWV3b3JrLWRldmVsb3BlciBtYWlsaW5nIGxpc3QNCglTcHJp bmdmcmFtZXdvcmstZGV2ZWxvcGVyQGxpc3RzLnNvdXJjZWZvcmdlLm5ldA0KCWh0dHBzOi8vbGlz dHMuc291cmNlZm9yZ2UubmV0L2xpc3RzL2xpc3RpbmZvL3NwcmluZ2ZyYW1ld29yay1kZXZlbG9w ZXINCgkNCg0K |
|
From: <tri...@tr...> - 2003-10-21 02:47:33
|
Juergen, > We don't need to address that at the DataSource level. Why not simply execute > the series of SQL operations within a transaction? With > DataSourceTransactionManager or HibernateTransactionManager, > DataSourceUtils.getConnection will always return the same Connection within a > thread-bound transaction. JtaTransactionManager depends on the JTA > implementation; any reasonable one with local transaction optimization will > return the same Connection within a transaction too. > I was not just thinking about the Petclinic. I can see a general need for running a series of SQL statements or procedcure calls thet depend on running within the same connection - maybe there is some database state kept at the connection level or for some other reason. If we want to use the available Spring JDBC objects like SqlUpdate and SqlQuery for this, then this type of data source might come in handy. Thomas |
|
From: <jue...@we...> - 2003-10-21 02:01:00
|
SSBzZWUsIHRoZXJlJ3MgYSBsaW1pdGF0aW9uIGluIHRlcm1zIG9mIGlzb2xhdGlvbiBsZXZlbC4g QnV0IGFzIHlvdSBzYWlkLCB0aGF0J3Mgbm90IGFuIGlzc3VlIHdpdGggdGhlIHNhbXBsZSBhcHAg YXQgYWxsLiBBY3R1YWxseSwgSSdtIGp1c3QgcGxheWluZyB3aXRoIHRoZSBpZGVudGl0eS1iYXNl ZCB2ZXJzaW9uLCBhbmQgaXQgd29ya3MgbGlrZSBhIGNoYXJtISBTd2l0Y2hpbmcgYmV0d2VlbiBK REJDIGFuZCBIaWJlcm5hdGUgb24g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9wZXJAbGlzdHMuc291cmNlZm9yZ2UubmV0DQoJaHR0cHM6Ly9saXN0cy5zb3VyY2Vmb3JnZS5u ZXQvbGlzdHMvbGlzdGluZm8vc3ByaW5nZnJhbWV3b3JrLWRldmVsb3Blcg0KCQ0KDQo= |
|
From: <jue...@we...> - 2003-10-21 17:13:53
|
Ken, everybody, I actually consider it as most effective to demonstrate portability = between both Hibernate/JDBC and HSQL/MySQL. IMO, it would just = complicate the implementation and thus make it harder to understand the = codebase if there were different id generation strategies within the = JDBC implementation, and switching to Hibernate just possible for one of = the two supported databases. I don't want to discredit the DataFieldMaxValueIncrementer support, it = definitely has value for strong portability requirements. It doesn't = match any Hibernate's way of id generation abstraction though, and I'd = like to make the code as easy as possible to understand for people that = already have a working knowledge of Hibernate. I've already committed the changes: All 4 combinations (Hibernate/HSQL, = Hibernate/MySQL, JDBC/HSQL, JDBC/MySQL) work nicely; the default is = Hibernate/HSQL now. When accessing the same database, the JDBC and = Hibernate implementations can work on exactly the same contents. = Furthermore, any data access is transactional now, via = TransactionProxyFactoryBean. Please give the stuff a review, if you like -- it's gonna get shipped = without much further refinement, as 1.0 M2 is about to be released this = week. Regards, Juergen P.S.: As a minor side note, I've removed the MySQL Connector 3.0 in the = lib-new directory as it is GPL; we're not allowed to distribute it = without becoming GPL ourselves. MySQL Connector 2.0.14 should be good = enough for the time being. -----Original Message----- From: Ken Krebs [mailto:kk...@kk...] Sent: Monday, October 20, 2003 11:41 PM To: spr...@li... Subject: [[W3-SPAM]] - Re: [Springframework-developer] Petclinic Hibernate implementation - Email found in subject It might be most useful to implement one of the 2 databases as is using=20 the MaxValueIncrementer while implementing the other using Hibernate to = preserve both types of examples. Ken j=FCrgen h=F6ller [werk3AT] wrote: >Thomas, Trevor, > > =20 > >>Does Hibernate use a different ID strategy for different databases? I = think >> =20 >> >what is implemented in the Petclinic is a strategy that would work the = same >across different databses as long as there is a MaxValueIncrementer = implementation. > >I intend to configure Hibernate to use "identity" for all databases. = Setting the correct Hibernate dialect will lead to "auto_increment" on = MySQL and "identity" on HSQL then. In terms of the data model, this = simply means dropping the sequence tables and defining the id columns as = "auto_increment" respectively "identity" in the DDL scripts. > >Sure, MaxValueIncrementer adopts a very generic approach that will work = on any database, even if it doesn't support such a thing like identity = columns. The disadvantage is that the mechanism is normally not native = to the database and thus somewhat tied to the application. > > =20 > >>If we change the Petclinic JDBC implementation to use identity = columns, then we >> =20 >> >need to figure out how to run the insert and subsequent query to = retrieve the id >using the same connection whether we are in a transaction or not. > >This is very similar with MySQL and HSQL: You simply run the insert = without specifying a value for the id field, and query "select = last_insert_id()" respectively "call identity()" afterwards (I've looked = up the latter in Hibernate's MySQLDialect and HSQLDialect = implementations). Petclinic already uses MySQLJdbcClinic and = HSQLJdbcClinic subclasses; it should be easy to encapsulate the = id-fetching query there. > >Of course, the range of possible Petclinic JDBC implementations will = then be bound to identity-supporting databases. According to the = Hibernate docs, those are "DB2, MySQL, MS SQL Server, Sybase and = HypersonicSQL". Oracle is notably absent; I think we can live with = Petclinic not running on Oracle, if we can allow for a dynamic switch = between JDBC and Hibernate on both MySQL and HSQL that way! > > =20 > >>>auto-increment just allows to read in the actual id afterwards >>> =20 >>> >>This is not reliable for concurrent inserts (which is why I generally = use sequences. For the sample this should be sufficient though. >> =20 >> > >According to what I found out about MySQL, "last_insert_id" returns the = last used id on the same connection and is thus transactionally safe. = Don't know about HSQL, but I frankly don't mind for sample purposes. > >Juergen > > >------------------------------------------------------- >This SF.net email sponsored by: Enterprise Linux Forum Conference & = Expo >The Event For Linux Datacenter Solutions & Strategies in The Enterprise = >Linux in the Boardroom; in the Front Office; & in the Server Room=20 >http://www.enterpriselinuxforum.com >_______________________________________________ >Springframework-developer mailing list >Spr...@li... >https://lists.sourceforge.net/lists/listinfo/springframework-developer > > > =20 > ------------------------------------------------------- This SF.net email is sponsored by OSDN developer relations Here's your chance to show off your extensive product knowledge We want to know what you know. Tell us and you have a chance to win $100 http://www.zoomerang.com/survey.zgi?HRPT1X3RYQNC5V4MLNSV3E54 _______________________________________________ Springframework-developer mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-developer |
|
From: Colin S. <col...@ex...> - 2003-10-20 15:47:57
|
Interesting, so in the case of sequences (Oracle sequences, in any case), Hibernate's save (or saveOrUpdate) will go and read the next sequence value from the db, so it can assign the id, but will not actually write the row until the flush. In the case of identity columns, it does an actual write immediately (as per your comment below), which makes sense, as it's the only way it can actually get the id value to assign to the objects as part of the save or saveOrUpdate. This all has interesting implications in a few respects, including performance. Basically, I think user or Hibernate assigned IDs (such as GUIDs) would perform best, since the db is not hit until the actual entity write, followed by a seqhilo (hilo which uses a sequence for one half the value), followed by a hilo, then sequences, then identity. jürgen höller [werk3AT] wrote: >Colin, Trevor, > >Session.save immediately inserts the object to the database, therefore it is able to set id into the object in any case. AFAIK, Session.update just inserts the object into the Session's object cache, to be flushed in the normal way. So Session.save seems to receive special treatment. > > > >>>auto-increment just allows to read in the actual id afterwards >>> >>> >>This is not reliable for concurrent inserts (which is why I generally use sequences. For the sample this should be sufficient though. >> >> > >This is not reliable even with proper transactions? Shouldn't "last_insert_id" or whatever it is called return the last inserted id in the same transaction, allowing for concurrent inserts in different transactions? > >Basically, the change for the sample would be straightforward: Drop all the manually handled sequence tables and turn the id columns into identity columns. This would allow for using Hibernate's out-of-the-box "identity" strategy; the JDBC implementation would have to do manual "last_insert_id" queries after the actual domain inserts. > >Juergen > > > -----Ursprüngliche Nachricht----- > Von: Colin Sampaleanu [mailto:col...@ex...] > Gesendet: Mo 20.10.2003 05:27 > An: spr...@li... > Cc: > Betreff: Re: [Springframework-developer] Petclinic Hibernate implementation > > > > jürgen höller [werk3AT] wrote: > > >Hi everybody, > > > >... > > > >BTW, we are using auto-increment for all MySQL databases at werk3AT, and it works nicely. I'd really like to understand the rationale for manual sequence handling. The only one I see is that the id can be determined before the domain insert/update statement this way, while auto-increment just allows to read in the actual id afterwards. But does that really matter for Petclinic? Wouldn't it be easier to use auto-increment/identity on both MySQL and HSQL? > > > > > > > Only somewhat related, but how does the auto-increment get handled > w/regards to Hibernate's 'save' function? That is, with an Oracle > sequence or some of the other (hi/lo, etc.) strategies, when you call > Hibernate's save function, your objects will get proper ids, even though > they don't get written to the db until they actually get flushed. This > is because the db has already been hit for the Oracle sequence or for > the manual sequence table column. > > What happens in your case with MySQL's auto-increment columns > (essentially similar to SQL Server's identity columns). Do the IDs stay > null (or whatever the unsaved value is) until Hibernate's flush actually > gets called? > Just curious since I've never used either MySQL or SQL Server with > Hibernate... > > Colin > > > |
|
From: Trevor C. <pr...@se...> - 2003-10-20 21:44:40
|
<me> auto-increment just allows to read in the actual id afterwards This is not reliable for concurrent inserts (which is why I generally = use sequences) </me> <juergen>=20 This is not reliable even with proper transactions? Shouldn't = "last_insert_id" or whatever it is called return the last inserted id in = the same transaction, allowing for concurrent inserts in different = transactions? </juergen> With transactions it should function properly. The problem is that with = transactions you have different locking strategies which have different = performance trade-offs depending on the level used. I've found that = using identity type fields makes transactions and specific locking = strategies required. By using a sequence, I can choose different = transaction/locking strategies depending on requirements/performance = (using the identity seems to limit my options). Also, it's generally a lot harder to change the db (especially the = primary key) after it's in production. I can do anything I want with = sequences, but I have more limited options with identity. If they work = today but not tomorrow, it's no longer a simple code change (and getting = burned by this a few times made me change to sequences as a default). = That's just my experience/preference. As I mentioned though, in this = case it should work correctly, and since it's a sample app changing the = db later is perfectly acceptable. Sorry I took us a little off-topic. Trevor |