Java/Hibernate Error: Connection leak detected. The internal connection pool has reached its maximum size and no connection is currently available
Solution 1:
I think you should also flush & close the session object before closing the factory object.
Solution 2:
Use below in your entity class @GeneratedValue(strategy = GenerationType.IDENTITY)
Solution 3:
In Student class, on Line no.14, you have declared the Id generation strategy as:
@GeneratedValue(strategy=GenerationType.AUTO)
Change it to
@GeneratedValue(strategy = GenerationType.IDENTITY)
This will remove the error.
Look in Hibernate Docs to find out which one is supported by your database. Below are all 4 Id generation strategies:
-
GenerationType.AUTO
: Pick an appropriate strategy for the particular database. -
GenerationType.IDENTITY
: Assign primary key using database identity column. -
GenerationType.SEQUENCE
: Assign primary keys using database sequence. -
GenerationType.TABLE
: Assign primary keys using an underlying database table to ensure uniqueness.