Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. public class HibernateUtil {
  2. private static final SessionFactory sessionFactory;
  3.  
  4. static {
  5. try {
  6. // Create the SessionFactory from hibernate.cfg.xml
  7. sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
  8. } catch (Exception ex) {
  9. // Make sure you log the exception, as it might be swallowed
  10. System.err.println("Initial SessionFactory creation failed." + ex);
  11. throw new ExceptionInInitializerError(ex);
  12. }
  13. }
  14.  
  15. public static SessionFactory getSessionFactory() {
  16. return sessionFactory;
  17. }
  18. }
  19.  
  20. <session-factory>
  21.  
  22. <property name="connection.driver_class">org.postgresql.Driver</property>
  23. <property name="connection.url">jdbc:postgresql://localhost:5432/dbName</property>
  24. <property name="connection.username">dbUsername</property>
  25. <property name="connection.password">dbPassword</property>
  26.  
  27. <property name="connection.pool_size">1</property>
  28. <property name="dialect">org.hibernatespatial.postgis.PostgisDialect</property>
  29. <property name="current_session_context_class">thread</property>
  30. <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
  31.  
  32. <property name="show_sql">true</property>
  33.  
  34. <mapping class="com.testapp.model.EntityClassWithAnnotations" />
  35.  
  36. </session-factory>
  37.  
  38. @Entity
  39. @Table(name = "table_name")
  40. public class MyEntityClass implements Serializable {
  41.  
  42. private static final long serialVersionUID = 1L;
  43.  
  44. @Id
  45. @GeneratedValue
  46. @Column(name = "gid")
  47. private Long gid;
  48.  
  49. @Column(name = "adm1_name")
  50. private String adminName;
  51.  
  52. @Column(name = "adm1_code")
  53. private String adminCode;
  54.  
  55. @Column(name = "pmal")
  56. private Double pmale;
  57.  
  58. @Column(name = "pfem")
  59. private Double pfemale;
  60.  
  61. @Type(type = "org.hibernatespatial.GeometryUserType")
  62. @Column(name = "the_geom", nullable = true)
  63. private Geometry geom;
  64.  
  65. public MyEntityClass() {}
  66.  
  67. public Long getGid() {
  68. return gid;
  69. }
  70.  
  71. public void setGid(Long gid) {
  72. this.gid = gid;
  73. }
  74.  
  75. public String getAdminName() {
  76. return adminName;
  77. }
  78.  
  79. public void setAdmin_name(String adminName) {
  80. this.adminName = adminName;
  81. }
  82.  
  83. public String getAdminCode() {
  84. return adminCode;
  85. }
  86.  
  87. public void setAdmin_code(String adminCode) {
  88. this.adminCode = adminCode;
  89. }
  90.  
  91. public Double getPmale() {
  92. return pmale;
  93. }
  94.  
  95. public void setPmale(Double pmale) {
  96. this.pmale = pmale;
  97. }
  98.  
  99. public Double getPfemale() {
  100. return pfemale;
  101. }
  102.  
  103. public void setPfemale(Double pfemale) {
  104. this.pfemale = pfemale;
  105. }
  106.  
  107. public Geometry getGeom() {
  108. return geom;
  109. }
  110.  
  111. public void setGeom(Geometry geom) {
  112. this.geom = geom;
  113. }
  114. }
  115.  
  116. <property name="hibernate.dialect" value="org.hibernate.spatial.dialect.postgis.PostgisDialect"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement