-->
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.  [ 2 posts ] 
Author Message
 Post subject: DB wird bei Neustart überschrieben
PostPosted: Fri May 26, 2006 4:44 am 
Newbie

Joined: Sun May 14, 2006 2:22 pm
Posts: 7
Hibernate version: 3.1.3

Name and version of the database you are using:HSQLDB 1.8.0

Problembeschreibung:
Wenn ich mein Hibernate Test Programm ausführe wird ein db script file angelegt (standalone modus). Mein Objekt wird schön gespeichert, soweit so gut.
Wenn ich das Programm jetzt noch mal aufrufe und ein weiteres Objekt abspeichern oder den Inhalt der DB laden möchte, bekomme ich aber ein Problem: Meine hsqldb script Datei wird einfach überschrieben und der Inhalt, der vorher darin gespeichert war, geht verloren.
Vermutlich habe ich in meiner hibernate.cfg.xml irgendetwas falsch gemacht. Bitte Hilfe.

Mapping documents:

++++++++++++++ hibernate.cfg.xml ++++++++++++++++++++

<?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="dialect">
org.hibernate.dialect.HSQLDialect
</property>

<property name="connection.driver_class">
org.hsqldb.jdbcDriver
</property>

<property name="connection.username">
sa
</property>

<property name="connection.password"></property>

<property name="connection.url">
jdbc:hsqldb:file:///Z:/prog/db/MyDB;shutdown=true
</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>

<mapping resource="de\test\XYZ.hbm.xml"/>

</session-factory>
</hibernate-configuration>


++++++++++++++XYZ.hbm.xml++++++++++++++++++++++++

<?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="de.test.XYZ" table="tbl_xyz">

<id name="id">
<generator class="native"/>
</id>

<property name="name" type="java.lang.String">
<column name="XYZname"/>
</property>

</class>
</hibernate-mapping>


Mein Code
Code:
public static void main(String[] args) {
      
      XYZ x = new XYZ();
      x.setName("Testname Abc89");
      x.saveOrUpdate();
      XYZ y = XYZ.load();

      System.out.println("Programm ENDE");

   }




und

Code:
   public synchronized void saveOrUpdate() {
      
      Session session = Hibernate.openSession();
      Transaction transaction = null;
      try {
         transaction = session.beginTransaction();
         session.saveOrUpdate(this);
         transaction.commit();
      }
      catch(HibernateException he) {
         if(transaction != null) {
            transaction.rollback();
            throw he;
         }
      }
      finally {
         Hibernate.closeSession(session);
         Hibernate.closeSessionFactory();
      }

   }
   
   public static synchronized XYZ load() {
      
      Session session = Hibernate.openSession();
      Transaction transaction = null;
      XYZ x = null;
      transaction = session.beginTransaction();
      Query query = session.createQuery("from XYZ");
      List result = query.list();   
      x = (XYZ) result.get(0);
      transaction.commit();
      
      System.out.println("x = " + x);

      Hibernate.closeSession(session);
      Hibernate.closeSessionFactory();
      
      return x;
      
   }
[/code]


Top
 Profile  
 
 Post subject: Problem fixed
PostPosted: Fri May 26, 2006 5:20 am 
Newbie

Joined: Sun May 14, 2006 2:22 pm
Posts: 7
OK, blöder Fehler:

<property name="hbm2ddl.auto">update</property>


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