-->
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.  [ 3 posts ] 
Author Message
 Post subject: session.save() speichert nicht
PostPosted: Thu Aug 03, 2006 5:05 am 
Newbie

Joined: Thu Aug 03, 2006 4:45 am
Posts: 5
Hallo,
wenn ich ein neues Objekt vom Typ Period erzeuge, session.save(p) und session.flush() aufrufe das Objekt trotzdem nicht in die Datenbank geschrieben wird. Wenn ich aber das speichern innerhalb einer Transaktion ablaufen lasse funktioniert es.

Meine hibernate.cfg.xml sieht so aus:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
        <property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
        <property name="hibernate.connection.password">QaiGon</property>
        <property name="hibernate.connection.url">jdbc:jtds:sqlserver://serverip/DB</property>
        <property name="hibernate.connection.username">sa</property>
        <property name="hibernate.default_schema">dbo</property>
        <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
        <mapping resource="model/Period.hbm.xml" />
    </session-factory>
</hibernate-configuration>


Meine mapping Datei:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="model.Period" table="Period">
        <id name="pkPeriod" type="long">
            <column name="pk_Period" />
            <generator class="identity" />
        </id>
        <property name="name" type="string">
            <column name="Name" length="50" not-null="true" />
        </property>
        <property name="dateFrom" type="timestamp">
            <column name="DateFrom" length="23" not-null="true" />
        </property>
        <property name="dateTo" type="timestamp">
           <column name="DateTo" length="23" not-null="true" />
        </property>
        <set name="events" inverse="true">
            <key>
                <column name="fk_Period" not-null="true" />
            </key>
            <one-to-many class="model.Event" />
        </set>
    </class>
</hibernate-mapping>


Und der Code der main():
Code:
Configuration con = new Configuration();
con.configure("hibernate.cfg.xml");

SessionFactory factory = con.buildSessionFactory();
Session session = factory.openSession();

//Transaction tx = session.beginTransaction();
Period p = new Period();
p.setName("Testperiode3");
p.setDateFrom(new GregorianCalendar(2007, 9, 1).getTime());
p.setDateTo(new GregorianCalendar(2007, 9, 31).getTime());
session.save(p);
//tx.commit();

session.flush();
session.close();
session = null;

factory.close();
factory = null;


Die Period Klasse besteht aus den privaten Datenelementen und den get-/set- Methoden (hab ich mir mit den hibernate tools erstellen lassen)
Ich benutze Hibernate 3.2.CR2 und die Hibernate Tools 3.2.0beta6a zusammen mit Eclipse 3.2

Vielleicht weiss jemand Rat.
vorab schonmal danke,
Gruß,
Matze


Last edited by MatzeGTO on Mon Sep 25, 2006 8:41 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 03, 2006 9:23 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Du musst den Aufruf innerhalb einer Transaktion laufen lassen.

Evtl. helfen Auto commit = true settings weiter, würde ich aber auf keinen Fall empfehlen.

_________________
Please don't forget to rate


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

Joined: Fri May 19, 2006 11:34 am
Posts: 29
Eine Transaktion ist eben genau dafür gedacht, Daten in eine DB zu schreiben. Nach dem Schreiben kann man entscheiden, ob man diese Transaktion gutheisst, und commites (d.h. das Speichern bestätigt), oder ob es sich hierbei um einen Irrtum handelt. Dann kann man nämlich das Speichern rückgängig machen, mit einem Rollback.

Viele Grüsse
Kai


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.