Thanks for the fast answer!
After adding
public class Students implements java.io.Serializable {
@GeneratedValue
private int id;
private String name;
private String address;
...
it says:
WARNING: SQL Error: -1, SQLState: 42Z23
2010-07-26 12:50:48 org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Attempt to modify an identity column 'ID'.
2010-07-26 12:50:48 org.hibernate.event.def.AbstractFlushingEventListener
performExecutions
SEVERE: Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: could not insert:
[desktopapplication1.Students]
I have also added
<id name="id" type="int">
<column name="ID" />
<generator class="increment"/>
</id>
Chris Wilson-24 wrote:
>
> 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.
>
>
--
View this message in context:
http://old.nabble.com/Hibernate-3-Outer-Join-Problem-tp28729781p29265219.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.