Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 休眠异常:内部连接池已达到其最大大小_Java_Hibernate - Fatal编程技术网

Java 休眠异常:内部连接池已达到其最大大小

Java 休眠异常:内部连接池已达到其最大大小,java,hibernate,Java,Hibernate,每当我向Id字段添加'@GeneratedValue'注释时,我都面临上述问题。 请参阅下面的代码片段,我使用它来使用hibernate保存实体 public class HibernateTest { public static void main(String[] args) { Employee emp1 = new Employee(); emp1.setName("User1"); try (SessionFactory sessionFactory = ne

每当我向Id字段添加'@GeneratedValue'注释时,我都面临上述问题。 请参阅下面的代码片段,我使用它来使用hibernate保存实体

public class HibernateTest {
public static void main(String[] args) {
    Employee emp1 = new Employee();
    emp1.setName("User1");

    try (SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession()){
    session.beginTransaction();
    session.save(emp1);
    session.getTransaction().commit();
    } catch (Exception e) {
        e.printStackTrace();
    }

}
}

下面是我的实体类

@Entity
@Table (name = "Employee_Details")
public class Employee {
    @Id  @GeneratedValue(strategy=GenerationType.AUTO)
    private int id;
    private String name;
    public int getId() { return id; }
    public void setId(int id) { this.id = id; } 
    public String getName() {
        return name;
    }
    public void setName(String name) { this.name = name; }
}
在hibernate.cfg.xml中,连接池大小设置为1

<property name="connection.pool_size">1</property>

如果我从Id字段中删除“GeneratedValue”注释,则效果良好。有谁能告诉我,为什么会失败?如何解决这个问题?

我遇到了这个问题,并通过更换:

@GeneratedValue(strategy = GenerationType.AUTO) 
与:


希望它对你也有用

我遇到了这个问题,通过更换:

@GeneratedValue(strategy = GenerationType.AUTO) 
与:


希望它对你也有用

我认为它使用连接来确定“id”。
也许将连接数设置为2而不是1可以解决问题。

我认为它使用连接来确定“id”。 也许将连接数设置为2而不是1可以解决问题

@GeneratedValue(strategy = GenerationType.IDENTITY)