Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <persistence xmlns="http://java.sun.com/xml/ns/persistence"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
  5. http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
  6. version="2.0">
  7.  
  8.  
  9. <persistence-unit name="postgreSQL">
  10. <provider>org.hibernate.ejb.HibernatePersistence</provider>
  11.  
  12. <properties>
  13. <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
  14.  
  15. <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/tfProjeto" />
  16.  
  17. <property name="javax.persistence.jdbc.user" value="postgres" />
  18. <property name="javax.persistence.jdbc.password" value="admin" />
  19.  
  20. <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
  21. <property name="hibernate.connection.CharSet" value="UTF-8" />
  22. <property name="hibernate.connection.characterEncoding" value="UTF-8" />
  23. <property name="hibernate.connection.useUnicode" value="true" />
  24.  
  25. <property name="hibernate.show_sql" value="true" />
  26. <property name="hibernate.format_sql" value="true" />
  27. <property name="hibernate.hbm2ddl.auto" value="update" />
  28.  
  29.  
  30. <property name="hibernate.c3p0.min_size" value="5" />
  31. <property name="hibernate.c3p0.max_size" value="10" />
  32. <property name="hibernate.c3p0.timeout" value="1800" />
  33. <property name="hibernate.c3p0.max_statements" value="50" />
  34.  
  35.  
  36. </properties>
  37. </persistence-unit>
  38.  
  39. <persistence-unit name="mySQL">
  40. <provider>org.hibernate.ejb.HibernatePersistence</provider>
  41.  
  42. <properties>
  43. <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
  44. <property name="javax.persistence.jdbc.url" value="jdbc:mysql:/localhost:3306/meuProjeto?zeroDateTimeBehavior=convertToNull" />
  45.  
  46. <property name="javax.persistence.jdbc.user" value="root" />
  47. <property name="javax.persistence.jdbc.password" value="admin" />
  48.  
  49. <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
  50. <property name="hibernate.connection.CharSet" value="UTF-8" />
  51. <property name="hibernate.connection.characterEncoding" value="UTF-8" />
  52. <property name="hibernate.connection.useUnicode" value="true" />
  53.  
  54. <property name="hibernate.show_sql" value="true" />
  55. <property name="hibernate.format_sql" value="true" />
  56. <property name="hibernate.hbm2ddl.auto" value="update" />
  57.  
  58.  
  59. <property name="hibernate.c3p0.min_size" value="5" />
  60. <property name="hibernate.c3p0.max_size" value="10" />
  61. <property name="hibernate.c3p0.timeout" value="1800" />
  62. <property name="hibernate.c3p0.max_statements" value="50" />
  63.  
  64.  
  65. </properties>
  66. </persistence-unit>
  67.  
  68. @RequestScoped
  69. public class EntityFactory implements Serializable {
  70. /**
  71. *
  72. */
  73. private static final long serialVersionUID = 1L;
  74. public static EntityManagerFactory entityManagerFactory;
  75. public static EntityManagerFactory entityManagerFactoryMySQL;
  76.  
  77. public static void initializeEntityManager() {
  78. if ((entityManagerFactory == null) || (!entityManagerFactory.isOpen())) {
  79. entityManagerFactory = Persistence
  80. .createEntityManagerFactory("postgreSQL");
  81. }
  82. }
  83.  
  84. public static void initializeEntityManagerMySql() {
  85. if ((entityManagerFactoryMySQL == null)
  86. || (!entityManagerFactoryMySQL.isOpen())) {
  87. entityManagerFactoryMySQL = Persistence
  88. .createEntityManagerFactory("mySQL");
  89. }
  90.  
  91. }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement