Hibernate: Schema wird nicht erstellt

chr_86

Grünschnabel
Hibernate: DB-Schema wird nicht erstellt

Hallo!

Habe einige Entity-Beans die ich mittels Hibernate Annotations in der Datenbank abbilden will. Problem ist, dass das Schema nicht angelegt wird. Dh. die Datenbank ist leer, es gibt keine Tabellen.
Erstaunlich wird doch geloggt:
Code:
763 [main] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - Running hbm2ddl schema update
763 [main] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - fetching database metadata
765 [main] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - updating schema
768 [main] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - schema update complete

Wo ist der Fehler? Datenbank ist MySQL 5.5.

---------------------------------- Weitere Infos ----------------------------------

Erstellen der Hibernate Session & Test ob Session erstellt werden kann
Code:
public class HibernateUtil {

    private static final SessionFactory sessionFactory = buildSessionFactory();

    private static SessionFactory buildSessionFactory() {
        try {
        	Configuration cfg = new Configuration();
        	cfg.addAnnotatedClass(ClassA.class);
        	cfg.addAnnotatedClass(ClassB.class)
        	cfg.addAnnotatedClass(ClassC.class)
        	
        	cfg.configure();        	
        	return cfg.buildSessionFactory();
        }
        catch (Throwable ex) { }
    }

    public static Session getSession() {
        return sessionFactory.openSession();
    }
}
Code:
public class HibernateTest {
	@Test
	public void test() {
		Session session = HibernateUtil.getSession();
		assertNotNull(session); // true, dh. != null
	}

Und die Config-Datei:
HTML:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
	<session-factory>
		<!-- Database connection settings -->
		<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
		<property name="connection.url">jdbc:mysql://localhost:3306/test</property>
		<property name="connection.username">root</property>
		<property name="connection.password"></property>
		<!-- Drop and re-create the database schema on startup -->
		<property name="hbm2ddl.auto">update</property>
	</session-factory>
</hibernate-configuration>
 
Zuletzt bearbeitet:
Müsste nicht auch angezeigt werden welche Tabelle schon vorhanden - bzw. auch nicht vorhanden sind?
Habe auch probiert bei der Konfiguration der Hibernate-Session den Export des Schemas manuell anzustoßen:
Code:
cfg.configure();        	
new SchemaExport(cfg).create(true, true);
Leider ohne Erfolg - die Datenbank bleibt leer.
 
Problem gelöst.
Ich habe org.hibernate.annotations.Entity für die @Entity Anotation verwendet. habe das mal gegen javax.persistence.Entity ausgetauscht und es funktioniert :) :) :)
 
Zurück