java - Spring hibernate Issue -


hibernate spring , maven im using hibernate 5 , spring 4 in personal project. unable find root cause of problem.

can me find out issue code?

<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"      xmlns:context="http://www.springframework.org/schema/context"     xmlns:tx="http://www.springframework.org/schema/tx"     xsi:schemalocation="http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd     http://www.springframework.org/schema/tx     http://www.springframework.org/schema/tx/spring-tx-3.0.xsd     http://www.springframework.org/schema/context     http://www.springframework.org/schema/context/spring-context-3.0.xsd">     <context:component-scan base-package="fr.geom.core.controller"/>     <context:component-scan base-package="fr.geom.core.service"/>     <context:component-scan base-package="fr.geom.core.repository"/>     <bean id="sessionfactory" class="org.springframework.orm.hibernate5.localsessionfactorybean">         <property name="datasource">             <ref bean="datasource" />         </property>         <property name="mappingresources">             <list>                 <value>lineentity.hbm.xml</value>                 <value>pointentity.hbm.xml</value>                 <value>polygoneentity.hbm.xml</value>                 <value>coordinate.hbm.xml</value>             </list>         </property>         <property name="hibernateproperties">             <props>                 <prop key="hibernate.dialect">org.hibernate.dialect.postgresqldialect</prop>                 <prop key="current_session_context_class">thread</prop>                 <prop key="show.provider_class">org.hibernate.cache.internal.nocacheprovider</prop>                 <prop key="show_sql">true</prop>                 <prop key="format_sql">true</prop>                 <prop key="hbm2ddl.auto">create</prop>             </props>         </property>     </bean>     <bean id="datasource" destroy-method="close" class="org.apache.commons.dbcp.basicdatasource">         <property name="driverclassname" value="org.postgresql.driver" />         <property name="url" value="jdbc:postgresql://localhost:5432/bdgeo" />         <property name="username" value="postgres" />         <property name="password" value="postgres" />     </bean> </beans>         package fr.geom.core.util;         import org.hibernate.sessionfactory;         import org.hibernate.cfg.configuration;         public class hibernateutil {             private static final sessionfactory sessionfactory = buildsessionfactory();              private static sessionfactory buildsessionfactory() {                 try {                     return new configuration().configure().buildsessionfactory();                 }                 catch (throwable ex) {                     system.err.println("initial sessionfactory creation failed." + ex);                     throw new exceptionininitializererror(ex);                 }             }             public static sessionfactory getsessionfactory() {                 return sessionfactory;             }         }          package fr.geom.core.util;          import org.hibernate.sessionfactory;         import org.hibernate.cfg.configuration;          public class hibernateutil {              private static final sessionfactory sessionfactory = buildsessionfactory();              private static sessionfactory buildsessionfactory() {                 try {                     return new configuration().configure().buildsessionfactory();                 }                 catch (throwable ex) {                     system.err.println("initial sessionfactory creation failed." + ex);                     throw new exceptionininitializererror(ex);                 }             }              public static sessionfactory getsessionfactory() {                 return sessionfactory;             }          }         package fr.geom.core.service;          import javax.annotation.resource;         import org.springframework.stereotype.service;         import fr.geom.core.entity.lineentity;         import fr.geom.core.geometrie.geometrie;         import fr.geom.core.repository.geometrydaointerface;          @service         public class lineservice implements geometryserviceinterface {               @resource             private geometrydaointerface linedao;              public lineentity loadservice(int id) {                 return (lineentity) linedao.load(id);             }              public void saveservice(geometrie line) {                 linedao.save(line);             }         }          package fr.geom.core.service;          import javax.annotation.resource;         import org.springframework.stereotype.service;         import fr.geom.core.entity.pointentity;         import fr.geom.core.geometrie.geometrie;         import fr.geom.core.repository.geometrydaointerface;           @service         public class pointservice implements geometryserviceinterface {              @resource             private geometrydaointerface pointdao;              public pointentity loadservice(int id) {                 return (pointentity) pointdao.load(id);             }              public void saveservice(geometrie point) {                 pointdao.save(point);             }          }          package fr.geom.core.service;          import javax.annotation.resource;         import org.springframework.stereotype.service;         import fr.geom.core.entity.polygoneentity;         import fr.geom.core.geometrie.geometrie;         import fr.geom.core.repository.geometrydaointerface;          @service         public class polygoneservice implements geometryserviceinterface {              @resource             private geometrydaointerface polygonedao;              public polygoneentity loadservice(int id) {                 return (polygoneentity) polygonedao.load(id);             }              public void saveservice(geometrie polygone) {                 polygonedao.save(polygone);             }          }           package fr.geom.core.repository;          import fr.geom.core.geometrie.geometrie;          public interface geometrydaointerface {              public void save(geometrie geometry);             public geometrie load(int id);         }         package fr.geom.core.repository;          import javax.annotation.resource;         import org.hibernate.session;         import org.hibernate.sessionfactory;         import org.springframework.stereotype.repository;         import fr.geom.core.entity.lineentity;         import fr.geom.core.geometrie.geometrie;         import fr.geom.core.util.hibernateutil;          @repository         public class linedao implements geometrydaointerface {              @resource             private sessionfactory sessionfactory = (sessionfactory) hibernateutil.getsessionfactory().getcurrentsession();              public void save(geometrie line) {                  try {                     session session = sessionfactory.opensession();                     session.begintransaction();                     session.save(line);                     session.gettransaction().commit();                     session.close();                  } catch (exception e) {                     // todo: handle exception                 }             }             public lineentity load(int id) {                 lineentity line = null;                 try {                     session session = sessionfactory.opensession();                     session.begintransaction();                     line = (lineentity) session.load(lineentity.class, id);                     session.gettransaction().commit();                     session.close();                  } catch (exception e) {                     // todo: handle exception                 }                     return line;             }         }          package fr.geom.core.repository;          import javax.annotation.resource;         import org.hibernate.session;         import org.hibernate.sessionfactory;         import org.springframework.stereotype.repository;         import fr.geom.core.entity.pointentity;         import fr.geom.core.geometrie.geometrie;         import fr.geom.core.util.hibernateutil;          @repository         public class pointdao implements geometrydaointerface {              @resource             private sessionfactory sessionfactory = (sessionfactory) hibernateutil.getsessionfactory().getcurrentsession();              public void save(geometrie point) {                  try {                     session session = sessionfactory.opensession();                     session.begintransaction();                     session.save(point);                     session.gettransaction().commit();                     session.close();                  } catch (exception e) {                     // todo: handle exception                 }              }             public pointentity load(int id) {                 pointentity point = null;                  try {                     session session = sessionfactory.opensession();                     session.begintransaction();                     point = (pointentity) session.load(pointentity.class, id);                     session.gettransaction().commit();                     session.close();                  } catch (exception e) {                     // todo: handle exception                 }                     return point;             }         }         package fr.geom.core.repository;          import javax.annotation.resource;         import org.hibernate.session;         import org.hibernate.sessionfactory;         import org.springframework.stereotype.repository;         import fr.geom.core.entity.polygoneentity;         import fr.geom.core.geometrie.geometrie;         import fr.geom.core.util.hibernateutil;          @repository         public class polygonedao implements geometrydaointerface {              @resource             private sessionfactory sessionfactory = (sessionfactory) hibernateutil.getsessionfactory().getcurrentsession();              public void save(geometrie polygone) {                  try {                     session session = sessionfactory.opensession();                     session.begintransaction();                     session.save(polygone);                     session.gettransaction().commit();                     session.close();                  } catch (exception e) {                     // todo: handle exception                 }              }              public polygoneentity load(int id) {                 polygoneentity polygone = null ;                 try {                     session session = sessionfactory.opensession();                     session.begintransaction();                     polygone = (polygoneentity) session.load(polygoneentity.class, id);                     session.gettransaction().commit();                     session.close();                  } catch (exception e) {                     // todo: handle exception                 }                 return polygone;             }package fr.geom.core.entity;          public class coordinate {              private int idcoordinate;             private double x;             private double y;              public coordinate() {              }              public int getidcoordinate() {                 return idcoordinate;             }              public void setidcoordinate(int idcoordinate) {                 this.idcoordinate = idcoordinate;             }              public double getx() {                 return x;             }              public void setx(double x) {                 this.x = x;             }              public double gety() {                 return y;             }              public void sety(double y) {                 this.y = y;             }         }          package fr.geom.core.entity;          import java.util.set;          import fr.geom.core.geometrie.geometrie;          public class lineentity implements geometrie{              private int idline;             private set<pointentity> line;              public lineentity(){             }             public int getidline() {                 return idline;             }             public void setidline(int idline) {                 this.idline = idline;             }             public set<pointentity> getline() {                 return line;             }              public void setline(set<pointentity> line) {                 this.line = line;             }             public string geotowkt() {                 // todo auto-generated method stub                 return null;             }             public string geomtogeojson() {                 // todo auto-generated method stub                 return null;             }             public string geomtogml() {                 // todo auto-generated method stub                 return null;             }         }          package fr.geom.core.entity;          import fr.geom.core.entity.coordinate;         import fr.geom.core.geometrie.geometrie;          public class pointentity implements geometrie{              private int idpoint;             private coordinate coordinate;              public pointentity(){             }             public int getidpoint() {                 return idpoint;             }             public void setidpoint(int idpoint) {                 this.idpoint = idpoint;             }             public coordinate getcoordinate() {                 return coordinate;             }             public void setcoordinate(coordinate coordinate) {                 this.coordinate = coordinate;             }              public string geotowkt() {                 // todo auto-generated method stub                 return null;             }              public string geomtogeojson() {                 // todo auto-generated method stub                 return null;             }              public string geomtogml() {                 // todo auto-generated method stub                 return null;             }         }          package fr.geom.core.entity;          import java.util.set;         import fr.geom.core.geometrie.geometrie;          public class polygoneentity implements geometrie{              private int idpolygone;             private set<pointentity> polygone;              public polygoneentity(){             }             public int getidpolygone() {                 return idpolygone;             }             public void setidpolygone(int idpolygone) {                 this.idpolygone = idpolygone;             }             public set<pointentity> getpolygone() {                 return polygone;             }             public void setpolygone(set<pointentity> polygone) {                 this.polygone = polygone;             }             public string geotowkt() {                 // todo auto-generated method stub                 return null;             }             public string geomtogeojson() {                 // todo auto-generated method stub                 return null;             }             public string geomtogml() {                 // todo auto-generated method stub                 return null;             }         }          package fr.geom.core.controller;          public interface geometrycontrollerinterface {              public void registergeometrie();             public void showgeometrie();         }          package fr.geom.core.controller;          import java.util.scanner;         import javax.annotation.resource;         import org.springframework.stereotype.controller;         import fr.geom.core.entity.lineentity;         import fr.geom.core.service.geometryserviceinterface;          @controller         public class linecontroller implements geometrycontrollerinterface {               @resource             private geometryserviceinterface lineservice;             private static final scanner key = new scanner(system.in);              public void registergeometrie() {                 lineentity line = new lineentity();                 system.out.println("___________________________");                 system.out.println("quel est l'identifiant de la line ?");                 int id = key.nextint();                 line.setidline(id);                 lineservice.saveservice(line);                 system.out.println("___________________________");                 system.out.println(" sauvegarde reussi .........");             }              public void showgeometrie() {                 system.out.println("___________________________");                 system.out.println("quel est l'identifiant de la line ? ");                 int id = key.nextint();                 lineservice.loadservice(id);                 system.out.println("___________________________");                 system.out.println(" chargement reussi ..^.. ");             }          }          package fr.geom.core.controller;          import java.util.scanner;         import javax.annotation.resource;         import org.springframework.stereotype.controller;         import fr.geom.core.entity.pointentity;         import fr.geom.core.entity.coordinate;         import fr.geom.core.service.geometryserviceinterface;          @controller         public class pointcontroller implements geometrycontrollerinterface{              @resource             private geometryserviceinterface pointservice;             private static final scanner key = new scanner(system.in);              public void registergeometrie() {                 pointentity point = new pointentity();                 coordinate coordinate = new coordinate();                 system.out.println("___________________________");                 system.out.println("quel est l'identifiant de la line ?");                 int id = key.nextint();                 point.setidpoint(id);;                 pointservice.saveservice(point);                 system.out.println("quelle est la valeur de x ? ");                 double x = key.nextdouble();                 coordinate.setx(x);                 system.out.println("quelle est la valeur de y ? ");                 double y = key.nextdouble();                 coordinate.sety(y);                 point.setcoordinate(coordinate);                 system.out.println("___________________________");                 system.out.println(" sauvegarde reussi .........");             }              public void showgeometrie() {                 system.out.println("___________________________");                 system.out.println("quel est l'identifiant du point ? ");                 int id = key.nextint();                 pointservice.loadservice(id);                 system.out.println("___________________________");                 system.out.println(" chargement reussi ..^.. ");             }         }          package fr.geom.core.controller;          import java.util.scanner;         import javax.annotation.resource;         import org.springframework.stereotype.controller;         import fr.geom.core.entity.polygoneentity;         import fr.geom.core.service.geometryserviceinterface;          @controller         public class polygonecontroller implements geometrycontrollerinterface {              @resource             private geometryserviceinterface polygoneservice;             private static final scanner key = new scanner(system.in);              public void registergeometrie() {                 polygoneentity polygone = new polygoneentity();                 system.out.println("___________________________");                 system.out.println("quel est l'identifiant du polygone ?");                 int id = key.nextint();                 polygone.setidpolygone(id);                 polygoneservice.saveservice(polygone);                 system.out.println("___________________________");                 system.out.println(" sauvegarde reussi .........");             }              public void showgeometrie() {                 system.out.println("___________________________");                 system.out.println("quel est l'identifiant du polygone ? ");                 int id = key.nextint();                 polygoneservice.loadservice(id);                 system.out.println("___________________________");                 system.out.println(" chargement reussi ..^.. ");             }         }          package fr.geom.core;          import org.springframework.context.applicationcontext;         import org.springframework.context.support.classpathxmlapplicationcontext;         import fr.geom.core.controller.linecontroller;         import fr.geom.core.controller.pointcontroller;         import fr.geom.core.controller.polygonecontroller;          /**          * app          *          */         public class app          {             public static  void main( string[] args )             {                    @suppresswarnings("resource")                 applicationcontext context = new classpathxmlapplicationcontext("applicationcontext.xml");                  pointcontroller pointcontroller = (pointcontroller) context.getbean("pointcontroller");                 pointcontroller.registergeometrie();                 pointcontroller.showgeometrie();                  linecontroller linecontroller = (linecontroller) context.getbean("linecontroller");                 linecontroller.registergeometrie();                 linecontroller.showgeometrie();                  polygonecontroller polygonecontroller = (polygonecontroller) context.getbean("polygonecontroller");                 polygonecontroller.registergeometrie();                 pointcontroller.showgeometrie();             }         }          <?xml version="1.0" encoding="utf-8"?>         <!doctype hibernate-mapping public           "-//hibernate/hibernate mapping dtd//en"          "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">          <hibernate-mapping>             <class name="fr.geom.core.entity.coordinate" table="coordinates">                 <id name="idcoordinate" column="id_coordinate">                     <generator class="identity">                     </generator>                 </id>                 <property name="x" column="x"></property>                 <property name="y" column="y"></property>             </class>         </hibernate-mapping>          <?xml version="1.0" encoding="utf-8"?>         <!doctype hibernate-mapping public           "-//hibernate/hibernate mapping dtd//en"          "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">           <hibernate-mapping>             <class name="fr.geom.core.entity.lineentity" table="lines">                 <id name="idline" column="id_line">                     <generator class="identity">                     </generator>                 </id>                 <set name="line" table="line_point">                     <key column="idline"/>                     <many-to-many class="fr.geom.core.entity.pointentity" column="idpoint"/>                 </set>             </class>         </hibernate-mapping>          <?xml version="1.0" encoding="utf-8"?>         <!doctype hibernate-mapping public           "-//hibernate/hibernate mapping dtd//en"          "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">          <hibernate-mapping>             <class name="fr.geom.core.entity.pointentity" table="points">                 <id name="idpoint" column="id_point">                     <generator class="identity">                     </generator>                 </id>                 <one-to-one name="coordinate" class="fr.geom.core.entity.coordinate"                     cascade="save-update"></one-to-one>             </class>         </hibernate-mapping>          <?xml version="1.0" encoding="utf-8"?>         <!doctype hibernate-mapping public           "-//hibernate/hibernate mapping dtd//en"          "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">          <hibernate-mapping>             <class name="fr.geom.core.entity.polygoneentity" table="polygones">                 <id name="idpolygone" column="id_polygone">                     <generator class="identity">                     </generator>                 </id>                 <set name="polygone" table="poly_point">                     <key column="idpolygone"/>                     <many-to-many class="fr.geom.core.entity.pointentity" column="idpoint"/>                 </set>             </class>         </hibernate-mapping> 

please can me ?

the errror sessionfactory.getcurrentsession() returns session, not sessionfactory, thereby class cast exception.

remove .getcurrentsession()

        @repository     public class linedao implements geometrydaointerface {          @resource         private sessionfactory sessionfactory = (sessionfactory) hibernateutil.getsessionfactory().getcurrentsession(); 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -