How do I get the generator Id before saving to database?

How to get generator id before save to database?I had search a lot,but it’s can resolve my problem. My probject is use spring mvc and hibernate and mysql.

import javax.persistence.*;

@Entity
@Table(name = "Test")
public class Test {
    private Integer id;
    private String name;


    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.TABLE,generator = "Test_gen")
    @TableGenerator(name = "Test_gen",table = "SerialNum",pkColumnName = 
    "tableName",valueColumnName = "tableValue",pkColumnValue = "Test")
    public Integer getId() {
       return id;
    }

    public void setId(Integer id) {
       this.id = id;
    }

    public String getName() {
       return name;
    }

    public void setName(String name) {
       this.name = name;
    }
}

Or how to use hibernate generator in other way? Like this:

public static long getGeneratorId(String entityName){
      return Hibernate.generatorId();
}

Here one of the solution to get the current table Identity, because you’re already using Hibernate you can use this line of code :

 session.CreateSqlQuery( "SELECT `AUTO_INCREMENT` " +
 "FROM  INFORMATION_SCHEMA.TABLES " +
 "WHERE TABLE_SCHEMA = 'Your_DB_NAME' "+
 "AND   TABLE_NAME   = 'Test' ").uniqueResult();