Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Set an auto-incremented key

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I want to set a auto-incremented key by myself. How to achieve this?

The class looks at the moment like this:


The corresponding field in the database has the auto-increment flag attached.

I am using JPA/Hibernate/MySQL/Tomcat. Btw.: I cannot change the database schema.

Edit:
If I set the id in an instance and commit it, I get this exception:



 
Juri Glass
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I removed the

and its working.

But now I have to submit for every instance an id. Nice would be something like:
If no id given, generate one.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic