[Solved] Hibernate :How does strategy GenerationType.Table works?

EverSQL Database Performance Knowledge Base

Hibernate :How does strategy GenerationType.Table works?

My Account entity Primary key is generated using GenerationType.Table stratergy.

@Entity
@Table(name="ACCOUNT")
public class Account {

@Id
@GeneratedValue(strategy=GenerationType.TABLE , generator="tablegenerator")
@TableGenerator(name="tablegenerator", table="ifinances_keys", pkColumnName="PK_NAME",valueColumnName="PK_VALUE")
@Column(name="ACCOUNT_ID")
private Long accountId;

I have defined a table ifinances_key to store this generated key and after persisting data , the following key is generated :-

Ifinances_Key Table

 PK_NAME,   PK_VALUE
 ACCOUNT    8

My Account Table has the following data :

ACCOUNT_ID | Rest of the columns ---->
200
300
350

When I run the following query

SELECT * FROM account a natural join ifinances_keys b ;

I am getting all the data ie :

ACCOUNT_ID | Rest of the columns ---->
200
300
350

Please explain the internal working of this strategy and how this Join is working?

How to optimize this SQL query?

The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:

  1. Description of the steps you can take to speed up the query.
  2. The optimal indexes for this query, which you can copy and create in your database.
  3. An automatically re-written query you can copy and execute in your database.
The optimization process and recommendations:
  1. Avoid Selecting Unnecessary Columns (query line: 2): Avoid selecting all columns with the '*' wildcard, unless you intend to use them all. Selecting redundant columns may result in unnecessary performance degradation.
The optimized query:
SELECT
        * 
    FROM
        account a NATURAL 
    JOIN
        ifinances_keys b

Related Articles



* original question posted on StackOverflow here.