• 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
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

GenerationType.AUTO

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I am trying a simple example using JPA with HSQLDB

When I try the above setting I get the exception :


When I try and use SEQUENCE it works fine

Questions ::
1 >
Istnt Auto meaning the persistence provider will choose the best strategy to generate PK ?
So why wastnt it able to do so ?

Regards,
-anagha
 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi anagha,

the API documentation says:

AUTO - Indicates that the persistence provider should pick an appropriate strategy for the particular database.



And this usually works as expected. The question is: What exactly are you trying to do? Without any code or error messages it's really hard for others to help you

Do you use the persist() method of the EntityManager instance? This is necessary to automatically get an auto-generated PK assigned to you entity!

Marco
 
author and cow tipper
Posts: 5000
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


javax.persistence.GenerationType.AUTO

The AUTO generation strategy is the default, and this setting simply chooses the primary key generation strategy that is the default for the database in question, which quite typically is IDENTITY, although it might be TABLE or SEQUENCE depending upon how the database is configured. The AUTO strategy is typically recommended, as it makes your code and your applications most portable.



Hibernate Generation Strategies Tutorial

The default should be IDENTITY, but it seems that is not happening in your application. One thing I might do is explicilty state IDENTITY as the auto-generation strategy, and see if it works. If it does, then something is wrong with the AUTO setting. If it doesn't, then it just looks like your database doesn't support IDENTITY.

Give it a try and report back.

-Cameron McKenzie
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic