Hi Umpirsky,
On Mon, 26 Jul 2010, umpirsky wrote:
> Sorry for jumping in like this, but since you have expirience with
> Hibernate and Derby, can you suggest any solution for working with
> generated keys? I have problem with primary keys, if I ommit them on
> insert, it fails, even if they are auto generated. Example table:
>
> CREATE TABLE students
> (
> id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY
> 1),
> name VARCHAR(24) NOT NULL,
> address VARCHAR(1024),
> CONSTRAINT primary_key PRIMARY KEY (id)
> ) ;
>
> Code:
>
> Students s = new Students();
> s.setName("Sasa");
> s.setAddress("Ulica");
> session.save(s);
>
> fails, because it generates SQL:
>
> insert into APP.STUDENTS (NAME, ADDRESS, ID) values (?, ?, ?)
>
> Any idea?
It shouldn't do that IF:
* You configure your ID column in your mapping as an appropriate
auto-generated type. (@GeneratedValue or equivalent should work).
* You use the correct dialect for Hibernate.
Cheers, Chris.
--
Aptivate | http://www.aptivate.org | Phone: +44 1223 760887
The Humanitarian Centre, Fenner's, Gresham Road, Cambridge CB1 2ES
Aptivate is a not-for-profit company registered in England and Wales
with company number 04980791.