I've tried everything and searched the forum and.
I can't get it right (may by I don't understand the whole concept)
I can't add a car to client.
The car data is filled out by user on the web page and client is already in the database.
And I get "Field 'id' doesn't have a default value"
I set id to <id name="carId"
column="id">
<generator class="native"/>
I don't get it ???
Please point me in the right direction.
public class Client extends ActionForm {
private int klient_id;
private String name;
private String surname;
private String region;
private int age;
private boolean male;
private Set cars = new HashSet();
}
public class CarBean extends ActionForm {
private int carId;
private int klient_id;
private String make;
private String type;
private int year;
private String distance;
private String capacity;
}
Hibernate version:3.0
Mapping documents: <hibernate-mapping package="pl.axmar" default-lazy="false">
<class name="Client" table="klient"> <comment>Lista klientow</comment> <id name="klient_id" column="id"> <generator class="native"/> </id> <property name="name" column="imie"/> <property name="surname" column="nazwisko"/> <property name="region" column="region"/> <property name="age" column="wiek"/> <property name="male" column="mezczyzna"/> <set name="cars"> <key column="klient_id"/> <one-to-many class="CarBean"/> </set>
</class>
</hibernate-mapping> <hibernate-mapping package="pl.axmar">
<class name="CarBean" table="pojazd"> <id name="carId" column="id"> <generator class="native"/> </id> <property name="make" column="marka"/> <property name="type" column="typ"/> <property name="year" column="rok"/> <property name="distance" column="przebieg"/> <property name="capacity" column="pojemnosc"/> </class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close(): Session ses= HibernateUtil.getSessionFactory().getCurrentSession(); ses.beginTransaction(); CarBean car=(CarBean)actionForm; ses.save(car);
Client cl= (Client) ses.load(Client.class,car.getKlient_id()); cl.getCars().add(car);
ses.getTransaction().commit();
Full stack trace of any exception that occurs: Field 'id' doesn't have a default value
Name and version of the database you are using:MySQL
The generated SQL (show_sql=true): Hibernate: insert into pojazd (marka, typ, rok, przebieg, pojemnosc) values (?, ?, ?, ?, ?)
Debug level Hibernate log excerpt:
|