This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Is Table sequencing the best sequence strategy? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Is Table sequencing the best sequence strategy?" Watch "Is Table sequencing the best sequence strategy?" New topic
Author

Is Table sequencing the best sequence strategy?

Nakataa Kokuyo
Ranch Hand

Joined: Jul 24, 2011
Posts: 184
Good day,

May I know whether "Table sequencing" is best among other sequence strategy in term of portable and performance?

FYI, I'm using mySQL for test environment and Oracle as production DB.

Thanks for sharing!!
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2247
    
    7

If I'm not mistaken, sequencing here means auto-increment right? Not knowing what your data is, this question is irrelevant.

K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

There probably isn't a single best strategy (the silver bullet), if it was, Hibernate wouldn't have any reason to support anything else.

For example, Oracle has sequences for this purpose and they perform and scale much better than selecting new values from table (at least when implemented and configured properly). But since some databases don't have sequences, they're obviously not the most portable solution. These two goals go somewhat against each other.

In the end, it depends on your needs. If you need the most scalable solution (say, thousands transactions per second), you'll probably have to lean towards the performance and forfeit the portability. If you'll be doing just a few transactions per second, portability might be more valuable to you than performance.

Scott's article about key generation might help you there, even if it doesn't concern Hibernate: Database Key Generation in Java Applications. The application key generators described there might be a good compromise (perform nearly as well as sequences), though they do need some setup first.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is Table sequencing the best sequence strategy?
 
Similar Threads
JPA and transactions: how to get last inserted record ID without flushing objects to the DB?
JPA Auto Incrementing EmbeddedId (Composit primary key values).
Migrating Toplink/ADF application to MySQL
Auto ID generation strategy in JPA
number puzzle