Guest User

Untitled

a guest
Nov 27th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. package fr.utils;
  2.  
  3. import org.hibernate.HibernateException;
  4. import org.hibernate.SessionFactory;
  5. import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
  6. import org.hibernate.cfg.Configuration;
  7.  
  8. public class HibernateConfig {
  9.  
  10. public static SessionFactory getConfiguredSessionFactory() throws HibernateException {
  11. try {
  12. Configuration config = new Configuration();
  13. config.configure();
  14. StandardServiceRegistryBuilder serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties());
  15. SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry.build());
  16. return sessionFactory;
  17. }
  18. catch (HibernateException e) {
  19. e.printStackTrace();
  20. return null;
  21. }
  22. }
  23. }
  24.  
  25. <?xml version='1.0' encoding='UTF-8'?>
  26. <!DOCTYPE hibernate-configuration PUBLIC
  27. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  28. "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  29.  
  30. <hibernate-configuration>
  31. <session-factory>
  32. <!-- SQL Dialect -->
  33. <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
  34.  
  35. <!-- Database Connection Settings -->
  36. <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  37. <property name="hibernate.connection.url">jdbc:mysql://localhost:8888/yugioh_j2ee</property>
  38. <property name="hibernate.connection.username">root</property>
  39. <property name="hibernate.connection.password"></property>
  40. <property name="hibernate.connection.pool_size">10</property>
  41. <property name="show_sql">true</property>
  42. <property name="hibernate.hbm2ddl.auto">update</property>
  43. <property name="spring.jpa.hibernate.ddl-auto">create</property>
  44.  
  45. <property name="hibernate.cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
  46. <!-- Specifying Session Context -->
  47. <property name="hibernate.current_session_context_class">org.hibernate.context.internal.ThreadLocalSessionContext</property>
  48.  
  49. <!-- Mapping With Model Class Containing Annotations -->
  50. <mapping class="fr.metier.Player"/>
  51. </session-factory>
  52. </hibernate-configuration>
Add Comment
Please, Sign In to add comment