2013-05-15 4 views

Antwort

101

Dies ist eine Hibernate.cfg.xml für Posgresql und es wird Ihnen helfen mit grundlegenden Hibernate-Konfigurationen für Posgresql.

<!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> 
     <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property> 
     <property name="hibernate.connection.driver_class">org.postgresql.Driver</property> 
     <property name="hibernate.connection.username">postgres</property> 
     <property name="hibernate.connection.password">password</property> 
     <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/hibernatedb</property> 



     <property name="connection_pool_size">1</property> 

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

     <property name="show_sql">true</property> 



     <mapping class="org.javabrains.sanjaya.dto.UserDetails"/> 

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

Das ist großartig, aber wo platziere ich diese Datei? In WEB-INF? –

+1

@HrishikeshChoudhari sollte es irgendwo in Ihrem Build-Pfad sein.Ich denke, WEB-INF wird gut.Ich habe nicht viel Verständnis für Web-Projekte, aber ich fühle, dass WEB-INF ist in den Build-Pfad. –

+9

org.hibernate.dialect.PostgreSQLDialect ist veraltet. sollten Sie org.hibernate.dialect.PostgreSQL82Dialect statt – long

5

Wenn das Projekt Maven es in src/main/resources platziert ist, in der Paket-Phase wird es kopiert in ../WEB-INF/classes/hibernate.cfg.xml

1

Dies ist die hibernate.cfg.xml Datei postgresql 9.5 zu verbinden und dies ist Hilfe Sie grundlegende Konfiguration.

<?xml version='1.0' encoding='utf-8'?> 

<!-- 
    ~ Hibernate, Relational Persistence for Idiomatic Java 
    ~ 
    ~ License: GNU Lesser General Public License (LGPL), version 2.1 or later. 
    ~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. 
    --> 
<!DOCTYPE hibernate-configuration SYSTEM 
     "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 
<hibernate-configuration 
> 
    <session-factory> 
     <!-- Database connection settings --> 
     <property name="connection.driver_class">org.postgresql.Driver</property> 
     <property name="connection.url">jdbc:postgresql://localhost:5433/hibernatedb</property> 
     <property name="connection.username">postgres</property> 
     <property name="connection.password">password</property> 

     <!-- JDBC connection pool (use the built-in) --> 
     <property name="connection.pool_size">1</property> 

     <!-- SQL dialect --> 
     <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</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.internal.NoCacheProvider</property> 

     <!-- Echo all executed SQL to stdout --> 
     <property name="show_sql">true</property> 

     <!-- Drop and re-create the database schema on startup --> 
     <property name="hbm2ddl.auto">create</property> 
     <mapping class="com.waseem.UserDetails"/> 
    </session-factory> 
</hibernate-configuration> 

Stellen Sie sicher, File Location unter src/main/resources/hibernate.cfg.xml

0

Ja unter Verwendung feder Boot mit Hibernate Konfigurationsdateien können wir die Daten bestehen bleiben sollte zur Datenbank. Halten Sie die Datei .cfg.xml im Ordner src/main/resources, um die mit der Datenbank verbundenen Konfigurationen zu lesen.

enter image description here

+1

Bitte ** [bearbeiten] ** Ihren Beitrag und zeigen Sie den tatsächlichen Code/XML als Text anstelle von Screenshots. Andere können Ihre Bilder nicht kopieren und einfügen. [Siehe hier] (https://meta.stackoverflow.com/a/285557/1402846) für Details. Vielen Dank. – Pang