Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 03.08.2006 00:21:12 by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
<class name="de.xxx.webapplication.kennzahlmgmt.jdo.Tbluser" table="tbluser" catalog="kenny">
<comment></comment>
<id name="idtblUser" type="int">
<column name="idtblUser" />
<generator class="assigned" />
</id>
<many-to-one name="tbldevison" class="de.xxx.webapplication.kennzahlmgmt.jdo.Tbldevison" fetch="select">
<column name="tblDevison_idtblDevison" not-null="true">
<comment></comment>
</column>
<column name="tblDevison_tblDevisonGroupe_idtblDevisonGroupe" not-null="true">
<comment></comment>
</column>
</many-to-one>
<property name="name" type="string">
<column name="name" length="45" not-null="true">
<comment></comment>
</column>
</property>
<property name="vorname" type="string">
<column name="vorname" length="45" not-null="true">
<comment></comment>
</column>
</property>
<property name="pwd" type="string">
<column name="pwd" length="20" not-null="true">
<comment></comment>
</column>
</property>
<property name="userid" type="string">
<column name="userid" length="20" not-null="true">
<comment></comment>
</column>
</property>
<property name="aktiv" type="java.lang.Boolean">
<column name="aktiv">
<comment></comment>
</column>
</property>
<property name="nummer" type="string">
<column name="nummer" length="45">
<comment></comment>
</column>
</property>
<set name="tblroleHasTblusers" inverse="true">
<key>
<column name="tblUser_idtblUser" not-null="true">
<comment></comment>
</column>
</key>
<one-to-many class="de.xxx.webapplication.kennzahlmgmt.jdo.TblroleHasTbluser" />
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Transaction myTransaction = null; //mySession.beginTransaction();;
try {
//Transaction öffnen
/*Transaction*/ myTransaction = mySession.beginTransaction();
//User Tabellen befüllen
Tbluser dbUser = new Tbluser();//(Tbluser)mySession.load(Tbluser.class, user.getId() );
dbUser.setAktiv(true);
dbUser.setName(user.getName());
dbUser.setNummer(user.getNummer());
dbUser.setPwd(user.getPasswort());
dbUser.setTbldevison(myDevison);
dbUser.setVorname(user.getVorname());
dbUser.setUserid(user.getKennung());
Integer newId = (Integer) mySession.save(dbUser);
myTransaction.commit();
} catch( HibernateException ex ) {
if( myTransaction != null )
try { myTransaction.rollback(); } catch( HibernateException exRb ) {}
throw new RuntimeException( ex.getMessage() );
} finally {
try { /*mySession.close();*/ } catch( Exception exCl ) {}
}
Name and version of the database you are using:MySQL 5.x
newId hat leider den Value 0 !? Wo ist denn die DB id die Aktuelle nach dem speichern ?