• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Which PK generator strategy to use in case of Batch Processing in Hibernate?

 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please provide an example to know how it works.
Thanks in advance.
 
Bartender
Posts: 2294
95
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Arun,
Have you read hibernate's documentation ? If not, here's a link for 5.4
https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#identifiers

I think it's unfair if you simply state a topic and ask others to write a full working code for you. Surely you are not asking that ?
 
Arun Singh Raaj
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been searching for the solution for an hour but couldn't make it. The docs link you provided tells which strategy not to use but not which one to use. I assume it tells you can use all except the IDENTITY.
I find only three types of PK generators to use with annotations that are IDENTITY, SEQUENCE AND TABLE.
I found about custom-generator too where you have to implement IdentifierGenerator interface but the example I saw executes the query to fetch the total count from db means it still depends on db on every insertions. I'm confused.
I don't tell anyone here to write the code but to atleast provide the name of the strategy that fits batch processing and a link that explains it.
Thanks.
 
Marshal
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Arun Singh Raaj wrote:The docs link you provided tells which strategy not to use but not which one to use. I assume it tells you can use all except the IDENTITY.



Yes, I would say that's a reasonable assumption.
 
Paul Clapham
Marshal
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's worth mentioning that "batch processing" may mean different things to you and me.

For me "batch processing" means "a process which updates or generates a (usually) large quantity of data without user interaction". An example might be the phone company generating monthly invoices for several hundred thousand customers.

It's possible that others might consider the use of java.sql.Statement.addBatch(SQL) and java.sql.Statement.executeBatch() to be "batch processing".

Those two concepts do overlap, of course, but it helps if we are all talking about the same thing when we use a technical term.

Also, the IDENTITY primary-key generator has the feature that you don't know the value of the generated key until after the SQL insert has finished. In practice this may or may not be an issue for you. For example you might be generating a few hundred thousand transactions, which need to have primary keys generated. But you might not need to know what those keys are while you're generating them, you just need to make sure that they exist and are unique.

However it's possible that Hibernate would need to know what the keys are; I haven't ever used Hibernate for this kind of application and I'm not sure I would ever use it either.

 
Master Rancher
Posts: 451
6
IntelliJ IDE Spring Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The hibernate docs have alot of examples.  The kind of PK you are using would depend on your data probably.  Why don't you just have an incremented ID if you have no idea what you need.  If you want to know how to do something with hibernate the docs are very detailed and have code examples.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!