-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Save liefert keine ID im Return zurück !!
PostPosted: Thu Aug 03, 2006 9:45 am 
Newbie

Joined: Tue Jul 11, 2006 6:04 am
Posts: 13
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 ?


Last edited by HellSing on Thu Aug 03, 2006 10:02 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 03, 2006 9:48 am 
Newbie

Joined: Tue Jul 11, 2006 6:04 am
Posts: 13
Ach so, in der DB gibt es dann ein Objekt mit einem stimmigen Primer...
leider nicht als Retunrwert in Java !


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 04, 2006 3:20 am 
Beginner
Beginner

Joined: Fri May 19, 2006 11:34 am
Posts: 29
Mit <generator class="assigned" /> muss eine eindeutige ID dem Objekt VOR dem Speichern zugewiesen werden. Dies passiert bei dir im Code jedoch nicht.

Wenn da ein Automatismus laufen soll, musst du auf andere Generatoren wie sequenze, increment oder identity zurückgreifen.

Viele Grüsse
Kai


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 04, 2006 12:19 pm 
Newbie

Joined: Tue Jul 11, 2006 6:04 am
Posts: 13
Hallo !

Danke für den Hinweis, ich habe in der Zwischenzeit auch nachgeforschtt
es scheint zu klappen wennman native angibt werde das aber noch genau am weekend prüfen :o)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.