[Hibernate] Configuration

hyperion

Bekanntes Mitglied
Hallo,

ich versuche gerade Hibernate für mein System einzurichten.

Mein System:
Applikationsserver: Glassfish v3
Datenbank: MySQL 5.5
Betriebssystem: Windows 7
IDE: Netbean 6.9.1
Connector: Connector/J 5.1.14

Angefangen hab ich damit, dass ich den Connecotr/J nach C:\glassfishv3\install\lib\ entpackt hab. Dann hab ich noch die Datei mysql-connector-java-5.1.14-bin direkt in das Verzeichnis C:\glassfishv3\install\lib\ kopiert weil ich mir nicht sicher war ob der Ordner oder nur das JAR-File dort sein muss.

Nachdem ich dannin Netbeans für mein Projekt eingestellt habe, dass ich Hibernate verwenden möchte, wurde eine Datei hibernate.cfg.xml für mich angelegt. Nachdem ich die Werte davon ein wenig angepasst ahbe sieht diese nun so aus:

Java:
<?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.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/webappdb</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">password</property>
  </session-factory>
</hibernate-configuration>

Wenn ich jetzt in Netbeans versuche den Hibernate Mapping Wizzard zu starten, kommt eine Fehlermeldung "Unable to connect. Cannot establish a connection to jdbc:mysql://localhost/webappdb using org.apache.derby.jdbc.ClientDriver (Unable to find a suitable driver)."

Mich verwundert es, dass da steht "...using org.apache.derby.jdbc.ClientDriver..." Dieser "Treiber" steht in meinem Configuration-File nirgends.

Was muss ich noch einstellen bzw. was muss ich ändern weil es aktuell noch falsch ist?

Gruß hyperion
 
Hier male eine hibernate.cfg die für Annotationen gedacht ist. Wird von mir benutzt und rennt wie sau...

Code:
 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "C:\\xml\\hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>

    <!-- ################################################################  -->
    <!--                       Servereinstellungen                         -->
    <!-- ################################################################  -->
    <!-- Lokale Datenbank -->
        <property name="connection.url">jdbc:mysql://localhost:3306/DBNAME</property>
        <property name="connection.username">root</property>
        <property name="connection.password">Server PW</property>

    <!-- ################################################################  -->
    <!--                    Treiber und Cacheeinstellungen                 -->
    <!-- ################################################################  -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <!--<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>-->

    <!-- Cacheeinstellungen -->
        <property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
        <property name="current_session_context_class">thread</property>
        <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

    <!-- ################################################################  -->
    <!--            Datenaktualisierungseinstellungen                      -->
    <!-- ################################################################  -->
   <property name="hibernate.hbm2ddl.auto">create</property>  <!-- hier werden alle Tabellen angelegt-->
    <!-- <property name="hibernate.hbm2ddl.auto">update</property> -->
        <property name="hibernate.show_sql">false</property>

    <!-- ################################################################  -->
    <!--            Mapping der vorhandenen Datenklassen                   -->
    <!-- ################################################################  -->
        <mapping class="package1.class1"/>
        <mapping class="package1.class2"/>
        <mapping class="package1.class1"/>
<!-- and so on -->
        

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

Neue Themen


Zurück
Oben