首页 > 解决方案 > java.sql.SQLTransientConnectionException: (conn=15) 表太多;MariaDB 在一个连接中只能使用 61 个表

问题描述

我是 JPA 的初学者,在从我的 DAO 访问数据库时,会弹出一个错误,指出 MariaDB 在连接中被限制为 61 个表。

这是实体代码的一部分

@Entity
@Table(name = "service")
@NamedQuery(name = "Department.findAll", query = "SELECT d FROM Department d")
public class Department implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column(name = "nom")
    private String name;

    private byte status;

    @OneToMany(mappedBy = "department", fetch = FetchType.EAGER)
    private Set<OperatingBloc> operatingBlocs;

    @OneToMany(mappedBy = "depatment", fetch = FetchType.EAGER)
    private Set<Room> rooms;
    ...
}

还有我的 DAO 代码的模型

@Stateless
public class DepartmentDAO implements DepartmentDAORemote, DepartmentDAOLocal {
    @PersistenceContext
    EntityManager em;

    @Override
    public List<Department> getAllDepartments() {
        return em.createNamedQuery("Department.findAll", Department.class).getResultList();
    }
    ...
}

每次我访问getAllDepartments()我的 DAO 的方法可能超过两次或三次时,我都会收到以下错误

org.hibernate.exception.JDBCConnectionException: could not extract ResultSet 
...
Caused by: java.sql.SQLTransientConnectionException: (conn=15) Too many tables; MariaDB can only use 61 tables in a join
...

我总共有 40 个表,因此有 40 个实体,每个实体的 DAO 编码方式与上述相同,所以我的问题与我可能做错的任何事情有关,以及我将如何纠正它。

数据库使用 JPA 2.2,MariaDB。

标签: hibernatejpamariadb

解决方案


推荐阅读