Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class HibernateUtil {
- private static final SessionFactory sessionFactory;
- static {
- try {
- // Create the SessionFactory from hibernate.cfg.xml
- sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
- } catch (Exception ex) {
- // Make sure you log the exception, as it might be swallowed
- System.err.println("Initial SessionFactory creation failed." + ex);
- throw new ExceptionInInitializerError(ex);
- }
- }
- public static SessionFactory getSessionFactory() {
- return sessionFactory;
- }
- }
- <session-factory>
- <property name="connection.driver_class">org.postgresql.Driver</property>
- <property name="connection.url">jdbc:postgresql://localhost:5432/dbName</property>
- <property name="connection.username">dbUsername</property>
- <property name="connection.password">dbPassword</property>
- <property name="connection.pool_size">1</property>
- <property name="dialect">org.hibernatespatial.postgis.PostgisDialect</property>
- <property name="current_session_context_class">thread</property>
- <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
- <property name="show_sql">true</property>
- <mapping class="com.testapp.model.EntityClassWithAnnotations" />
- </session-factory>
- @Entity
- @Table(name = "table_name")
- public class MyEntityClass implements Serializable {
- private static final long serialVersionUID = 1L;
- @Id
- @GeneratedValue
- @Column(name = "gid")
- private Long gid;
- @Column(name = "adm1_name")
- private String adminName;
- @Column(name = "adm1_code")
- private String adminCode;
- @Column(name = "pmal")
- private Double pmale;
- @Column(name = "pfem")
- private Double pfemale;
- @Type(type = "org.hibernatespatial.GeometryUserType")
- @Column(name = "the_geom", nullable = true)
- private Geometry geom;
- public MyEntityClass() {}
- public Long getGid() {
- return gid;
- }
- public void setGid(Long gid) {
- this.gid = gid;
- }
- public String getAdminName() {
- return adminName;
- }
- public void setAdmin_name(String adminName) {
- this.adminName = adminName;
- }
- public String getAdminCode() {
- return adminCode;
- }
- public void setAdmin_code(String adminCode) {
- this.adminCode = adminCode;
- }
- public Double getPmale() {
- return pmale;
- }
- public void setPmale(Double pmale) {
- this.pmale = pmale;
- }
- public Double getPfemale() {
- return pfemale;
- }
- public void setPfemale(Double pfemale) {
- this.pfemale = pfemale;
- }
- public Geometry getGeom() {
- return geom;
- }
- public void setGeom(Geometry geom) {
- this.geom = geom;
- }
- }
- <property name="hibernate.dialect" value="org.hibernate.spatial.dialect.postgis.PostgisDialect"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement