Ok thanks, this works fine! Now i want to save a reference from Ressource in the class Termin. Please look here:
Code:
public class Termin implements Serializable {
private Ressource ressource; <-the reference
private long id;
private String kommentar;
public Ressource getRessource()
{
return ressource;
}
public void setRessource(Ressource r)
{
ressource = r;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getKommentar() {
return kommentar;
}
public void setKommentar(String kommentar) {
this.kommentar = kommentar;
}
Termin.hbm.xml:
Code:
<hibernate-mapping>
<class name="uebung9bPackage.Termin" table="termin">
<id name="id" column="id" type="long">
<generator class="native"/>
</id>
<property name="kommentar" column="kommentar" type="string" />
<many-to-one class="uebung9bPackage.Ressource" name="ressource" column="resid" cascade="all"/>
</class>
</hibernate-mapping>
Table "Termin":
Code:
CREATE TABLE `termin` (
`id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`kommentar` VARCHAR( 100 ) NOT NULL ,
`resid` BIGINT NOT NULL
) TYPE = innodb;
When i try to save the class Termin like this:
Code:
Termin term = new Termin();
Raum raum = new Raum();
term.setRessource(raum);
session.save(term);
this error shows up:
Code:
Exception in thread "main" org.hibernate.exception.ConstraintViolationException: could not insert: [uebung9bPackage.Termin]
Caused by: java.sql.SQLException: Column 'resid' cannot be null
Hope you can help me with this last problem. Thanks!!!