This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes @Generatedvalue and MySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "@Generatedvalue and MySQL" Watch "@Generatedvalue and MySQL" New topic

@Generatedvalue and MySQL

Kamil Kuchta

Joined: Mar 09, 2009
Posts: 17
I can't generate id value in MySQL using @Generatedvalue.
SQLException: no value for 2 parameter in exprection INSERT INTO tab(value, id) values(?, ?)

I tried to use everything what is in commentary

Thanks for help!
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299

Is the column in the database defined correctly as a auto increment column?

GenRocket - Experts at Building Test Data
Kamil Kuchta

Joined: Mar 09, 2009
Posts: 17
Exactly. PrimaryKey, Integer, NotNull, Auto Inc, Unsigned, Zerofill
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

Normally if you have a column where unique keys are auto-generated, you leave that column out of your INSERT statements.
Consider Paul's rocket mass heater.
subject: @Generatedvalue and MySQL
Similar Threads
JPA,/mysql/JBoss and a big head ache
hibernate to JPA: generator class=increment
Leaving any property unmapped to a column in Hibernate using annotation
EJB with multiple MapKeys
HBM to Annotation: Foreign Generator