Skip to content

Instantly share code, notes, and snippets.

@anas-didi95
Last active August 10, 2022 18:10
Show Gist options
  • Save anas-didi95/ca1802753ea5c2238ad7cfad81b0cca4 to your computer and use it in GitHub Desktop.
Save anas-didi95/ca1802753ea5c2238ad7cfad81b0cca4 to your computer and use it in GitHub Desktop.
hibernate_hibernate.cfg.xml
<?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>
<property name="hbm2ddl.auto">update</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="connection.url">jdbc:oracle:thin:@127.0.0.1:1521:xe</property>
<property name="connection.username">system</property>
<property name="connection.password">password</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="show_sql">true</property>
<mapping class="models.User"/>
<mapping class="models.LogHistory"/>
</session-factory>
</hibernate-configuration>
@anas-didi95
Copy link
Author

anas-didi95 commented Jul 19, 2018

hibernate.cfg.xml Properties

Name Description
hbm2ddl.auto Automatically validates or exports schema DDL to the database when the SessionFactory is created.
Disable when omitted.
Available options:
- validate: validate the schema, make no changes to the database.
- update: update the schema.
- create: creates the schema, destroying previous data.
- create-drop: drop the schema when the SessionFactory is closed explicitly, when the application is stopped.
http://stackoverflow.com/questions/438146/ddg#1689769
https://stackoverflow.com/questions/3179765/how-to-turn-off-hbm2ddl
dialect Makes Hibernate generate the appropriate SQL for the chosen database.
Available options:
- MySQL: org.hibernate.dialect.MySQLDialect
- Oracle (any version): org.hibernate.dialect.OracleDialect
- PostgreSQL: org.hibernate.dialect.PostgreSQLDialect
https://www.tutorialspoint.com/hibernate/hibernate_configuration.htm
connection.url JDBC URL to the database instance.
Available options:
- MySQL: jdbc:mysql://localhost:3306/SampleDB
- Oracle: jdbc:oracle:thin:@127.0.0.1:1521:xe
- PostgreSQL: jdbc:postgresql://localhost:5432/hibernatedb
connection.username Database username.
connection.password Database password.
connection.driver_class JDBC driver class
Available options:
- MySQL: com.mysql.jdbc.Driver
- Oracle: oracle.jdbc.driver.OracleDriver
- PostgreSQL: org.postgresql.Driver
show_sql Display Hibernate SQL to console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment