Skip to content

Instantly share code, notes, and snippets.

@thjanssen
Last active March 17, 2017 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thjanssen/f0a9575d236e2792f1f3c110342f1443 to your computer and use it in GitHub Desktop.
Save thjanssen/f0a9575d236e2792f1f3c110342f1443 to your computer and use it in GitHub Desktop.
ServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().configure()
.build();
SessionFactory sessionFactory = new MetadataSources(standardRegistry).addAnnotatedClass(Author.class)
.buildMetadata()
.buildSessionFactory();
Session session = sessionFactory.openSession();
<hibernate-configuration>
<session-factory>
<property name="dialect">
org.hibernate.dialect.PostgreSQLDialect
</property>
<property name="connection.driver_class">
org.postgresql.Driver
</property>
<property name="connection.url">
jdbc:postgresql://localhost:5432/recipes
</property>
<property name="connection.username">postgres</property>
<property name="connection.password">postgres</property>
<property name="connection.pool_size">1</property>
<property name="hbm2ddl.auto">create</property>
</session-factory>
</hibernate-configuration>
Author a = new Author();
a.setFirstName("Thorben");
a.setLastName("Janssen");
session.persist(a);;
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.8.Final</version>
</dependency>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment