Exception in thread "main" org.hibernate.Ausnahme.LockAcquisitionException: could not execute-Anweisung

Ich bin versucht, zu aktualisieren einen Datensatz in der Tabelle mit Hibernate, aber der Datensatz wird nicht aktualisiert und auf der nächsten Ausführung dauert es viel Zeit und wirft folgende Fehler: Exception in thread "main" org.hibernate.exception.LockAcquisitionException: could not execute statement

Mitarbeiter:

    import javax.persistence.CascadeType;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    import javax.persistence.OneToOne;
    import javax.persistence.Table;

    import org.hibernate.annotations.*;

    @Entity
    @Table(name = "Emp_Table")
    public class Employee {
        @Id
        @GeneratedValue
        private int id;
        private String name;
        private double salary;

        @OneToOne(mappedBy = "emp")
        @Cascade(value = org.hibernate.annotations.CascadeType.ALL)
        private Address addr;

        /* Getter-Setter methods */
    }

Adresse:

    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    import javax.persistence.OneToOne;
    import javax.persistence.PrimaryKeyJoinColumn;
    import javax.persistence.Table;

    import org.hibernate.annotations.GenericGenerator;
    import org.hibernate.annotations.Parameter;

    @Entity
    @Table(name = "Addr_Table")
    public class Address {

        @Id
        @Column(name = "eid")
        @GeneratedValue(generator = "gen")
        @GenericGenerator(name = "gen", strategy = "foreign", parameters = {@Parameter(name = "property", value = "emp")})
        private int id;
        private String state;
        private String country;

        @OneToOne
        @PrimaryKeyJoinColumn
        private Employee emp;

        /* Getter-Setter methods */
    }

HQLExample enthält die CRUD-operation.

package com.Hibernate.Main;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import com.Hibernate.Model.Employee;
import com.Hibernate.Util.HibernateUtil;

public class HQLExample {

    @SuppressWarnings("unchecked")
    public static void main(String[] args) {

        SessionFactory factory = new Configuration().configure().buildSessionFactory();
        Session session = factory.openSession();

        Transaction tx = session.beginTransaction();
        Query query = session.createQuery("from Employee");
        List<Employee> emp = query.list();
        for (Employee empList : emp) {
            System.out.println("\nID:\t" + empList.getId() + "\nName:\t" + empList.getName() + "\nSalary:\t"
                    + empList.getSalary());
        }

        Query query1 = session.createQuery("from Employee where id = :id");
        query1.setInteger("id", 2);
        Employee empList = (Employee) query1.uniqueResult();
        System.out.println(
                "\nID:\t" + empList.getId() + "\nName:\t" + empList.getName() + "\nSalary:\t" + empList.getSalary());


        Query query2 = session.createQuery("from Employee");
        query2.setFirstResult(1);
        query2.setFetchSize(1);
        emp = query2.list();
        for (Employee empList1 : emp) {
            System.out.println("\nID:\t" + empList1.getId() + "\nName:\t" + empList1.getName() + "\nSalary:\t"
                    + empList1.getSalary());
        }

        query = session.createQuery("update Employee set name = :name where id = :id");
        query.setParameter("name", "Gaurav");
        query.setInteger("id", 2);
        int result = query.executeUpdate();
        System.out.println("\n\nEmployee updated successfully: "+result);



        query = session.createQuery("delete from Employee where id: eid");
        query.setInteger("eid", 4);
        result = query.executeUpdate();
        System.out.println("Employee deleted successfully "+ result);*/
    }
}

Ich bin in der Lage, um die Datensätze abzurufen, aber während der Aktualisierung der Datensatz entweder nicht den Datensatz aktualisieren, oder dauert eine lange Zeit und wirft den Fehler: Exception in thread "main" org.hibernate.Ausnahme.LockAcquisitionException: could not execute-Anweisung.

Mit dem Befehl show processlist und ich hatte versucht, den Prozess zu beenden, dort, wo in den sleep-Modus. Nach dem töten dieser Prozess, den ich bin in der Lage zu führen Sie die update-Anweisung, aber es wird nicht übernommen in die Datenbank. Wenn er versucht wird, um den code auszuführen, wieder gehen zu lange laufen-und scheitert.

hibernate.cfg.xml:

<?xml version="1.0" encoding="utf-8"?>
 <!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">root.123</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/Hibernate</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <property name="hibernate.show_sql">true</property>
        <mapping class="com.Hibernate.Model.Address"></mapping>
        <mapping class="com.Hibernate.Model.Employee"></mapping>
    </session-factory>
</hibernate-configuration>
  • hibernate.cfg.xml Datei:
InformationsquelleAutor Ranju Pillai | 2017-03-07
Schreibe einen Kommentar