-->
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: Datenbank leer
PostPosted: Sun Jan 22, 2006 12:19 pm 
Newbie

Joined: Sun Jan 22, 2006 12:04 pm
Posts: 5
Hibernate version: 3:1
DB: HSQLDB 1.8.0.2

Ich versuche gerade ein beispiel zum laufen zu kriegen, das ein Objekt anlegt und dann in der DB speichert.
Alles scheint gut zu gehen, aber hinterher ist die DB leer.

Hier mein Code:

mapping:

<?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 package="org.jazzanowak.hibernate">
<class name="FanClub" table="FANCLUB">
<id name="id" column="ID">
<generator class="native"/>
</id>
<property name="name" column="NAME"/>
</class>
</hibernate-mapping>

conf:

<!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="current_session_context_class">thread</property>
<property name="cache.provider_class">
org.hibernate.cache.NoCacheProvider
</property>
<property name="connection.url">
jdbc:hsqldb:file:F:/Developing/workspace/LearningHibernate/data/fans
</property>
<property name="hbm2ddl.auto">create</property>
<property name="show_sql">true</property>
<mapping resource="FanClub.hbm.xml"/>
</session-factory>
</hibernate-configuration>


Code:

public class Main {

private SessionFactory sessionFactory;

Log logger = LogFactory.getLog(Main.class);

public Main() {
try {
logger.info("Creating session Factory");
Configuration cfg = new Configuration().configure();
sessionFactory = cfg.buildSessionFactory();
} catch( HibernateException ex ) {
ex.printStackTrace();
System.exit( 5 );
}
}

public void close() {
sessionFactory.close();
}

public static void main(String[] args) throws Exception {
Main main = new Main();
main.addFanClub("Die jans");
main.showFanClubs();
main.close();
}

private void addFanClub(String name) {
Session sess = null;
try {
sess = sessionFactory.openSession();
sess.beginTransaction();
FanClub fanClub = new FanClub();
fanClub.setName(name);
sess.save( fanClub );
sess.getTransaction().commit();
} catch( HibernateException ex ) {
logger.error("Someting failed ",ex);
} finally {
sess.close();
}
}

private void showFanClubs() {
org.hibernate.Session sess = null;
try {
sess = sessionFactory.openSession();
System.out.println("\nFanclubs:");
List kunden = sess.createQuery("from FanClub").list();
for (int i = 0; i < kunden.size(); i++) {
FanClub fanClub = (FanClub) kunden.get(i);
logger.info("FanClub: " + fanClub.toString());
}
} catch (HibernateException ex) {
logger.error("Error while reading from db", ex);
} finally {
sess.close();
}
}
}

Die FanClub Klasse ist ein simples Bean.

Vielen Dank


Top
 Profile  
 
 Post subject: lösung
PostPosted: Sun Jan 22, 2006 1:14 pm 
Newbie

Joined: Sun Jan 22, 2006 12:04 pm
Posts: 5
okay ich habe die lösung:
hibernate.connection.shutdown=true


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.