Created a project connected to a remote host via hibernate. Everything is ok, but here's the trouble if I do an action (let's say I add a line to the database through a web application), it adds, but if I refresh the page, the lines will be added again, the same trouble with deletion. After any action it is worth updating the page, the project will be updated back with the last action. I post my code below. Help how to fix it. Thank
<session-factory> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://****/****?zeroDateTimeBehavior=convertToNull</property> <property name="hibernate.connection.username">*****</property> <property name="hibernate.connection.password">*****</property> <property name="connection.pool_size">1</property> <property name="hbm2ddl.auto">update</property> <property name="show_sql">true</property> <property name="connection.autocommit">false</property> <property name="hibernate.c3p0.max_size">1</property> <property name="hibernate.c3p0.min_size">0</property> <property name="hibernate.c3p0.timeout">5000</property> <property name="hibernate.c3p0.max_statements">1000</property> <property name="hibernate.c3p0.idle_test_period">300</property> <property name="hibernate.c3p0.acquire_increment">1</property> <property name="hibernate.current_session_context_class">thread</property> <mapping class="entity.InformationAboutTheDriver"/> here is revenge
<property name="hibernate.current_session_context_class">thread</property> <mapping class="entity.InformationAboutTheDriver"/> Here is the controller
package controller; import entity.*; import java.util.*; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import model.*; /** * * @author Elvir */ @ManagedBean(name="iatdContrl") @SessionScoped public class IatdController { private List<InformationAboutTheDriver> lst = new ArrayList<InformationAboutTheDriver>(); public List<InformationAboutTheDriver> getLst() { Employee_dao dao=new Employee_dao(); return dao.getAll(); } public void setLst(List<InformationAboutTheDriver> lst) { this.lst = lst; } private InformationAboutTheDriver informationAboutTheDriver= new InformationAboutTheDriver(); public InformationAboutTheDriver getInformationAboutTheDriver() { return informationAboutTheDriver; } public void setInformationAboutTheDriver(InformationAboutTheDriver informationAboutTheDriver) { this.informationAboutTheDriver = informationAboutTheDriver; } public void remove (InformationAboutTheDriver aboutTheDriver){ Employee_dao dao = new Employee_dao(); dao.remove(aboutTheDriver); } public String insert (){ Employee_dao dao=new Employee_dao(); dao.create(informationAboutTheDriver); return "index"; } public String edit(InformationAboutTheDriver aboutTheDriver){ this.informationAboutTheDriver=aboutTheDriver; return "edit"; } public String save(){ Employee_dao dao=new Employee_dao(); dao.edit(informationAboutTheDriver); return "index"; } } Here is the data DB
@Entity @Table(name="information_about_the_driver" ,catalog="***" ) public class InformationAboutTheDriver implements java.io.Serializable { private Integer id; private String name; private String latitude; private String longitude; private String number; public InformationAboutTheDriver() { } public InformationAboutTheDriver(String name, String latitude, String longitude, String number) { this.name = name; this.latitude = latitude; this.longitude = longitude; this.number = number; } @Id @GeneratedValue(strategy=IDENTITY) @Column(name="id", unique=true, nullable=false) public Integer getId() { return this.id; } public void setId(Integer id) { this.id = id; } @Column(name="Name", nullable=false) public String getName() { return this.name; } public void setName(String name) { this.name = name; } @Column(name="Latitude", nullable=false) public String getLatitude() { return this.latitude; } public void setLatitude(String latitude) { this.latitude = latitude; } @Column(name="Longitude", nullable=false) public String getLongitude() { return this.longitude; } public void setLongitude(String longitude) { this.longitude = longitude; } @Column(name="Number", nullable=false) public String getNumber() { return this.number; } public void setNumber(String number) { this.number = number; } } Well, here
package model; import java.util.*; import entity.*; import org.hibernate.*; public class Employee_dao { public List<InformationAboutTheDriver> getAll(){ Session s=HibernateUtil.getSessionFactory() .getCurrentSession(); List<InformationAboutTheDriver> lst = new ArrayList<>(); try { s.beginTransaction(); lst=s.createCriteria(InformationAboutTheDriver.class).list(); s.getTransaction().commit(); } catch (Exception e) { e.printStackTrace(); s.getTransaction().rollback(); } return lst; } public void create(InformationAboutTheDriver aboutTheDriver){ Session s = HibernateUtil.getSessionFactory() .getCurrentSession(); try { s.beginTransaction(); s.save(aboutTheDriver); s.getTransaction().commit(); } catch (Exception e) { e.printStackTrace(); s.getTransaction().rollback(); } } public void edit(InformationAboutTheDriver aboutTheDriver){ Session s = HibernateUtil.getSessionFactory() .getCurrentSession(); try { s.beginTransaction(); s.update(aboutTheDriver); s.getTransaction().commit(); } catch (Exception e) { e.printStackTrace(); s.getTransaction().rollback(); } } public void remove (InformationAboutTheDriver aboutTheDriver){ Session s = HibernateUtil.getSessionFactory() .getCurrentSession(); try { s.beginTransaction(); s.delete(aboutTheDriver); s.getTransaction().commit(); } catch (Exception e) { e.printStackTrace(); s.getTransaction().rollback(); } } } Well, just a scrap class
import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.SessionFactory; /** * Hibernate Utility class with a convenient method to get Session Factory * object. * * @author Elvir */ public class HibernateUtil { private static final SessionFactory sessionFactory; static { try { // Create the SessionFactory from standard (hibernate.cfg.xml) // config file. sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory(); } catch (Throwable ex) { // Log the exception. System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } } public static SessionFactory getSessionFactory() { return sessionFactory; } } Who is not difficult to help. I really need help in the morning stuck on this problem and just can not fix it