Is there any downside to using identity generator directly using code such as...
Code:
EntityManager em = ...;
HibernateEntityManager hibEM = (HibernateEntityManager) em;
Session session = hibEM.getSession();
SessionFactoryImpl sessionFactoryImpl = (SessionFactoryImpl) session.getSessionFactory();
IdentifierGenerator identifierGenerator = sessionFactoryImpl.getIdentifierGenerator("com.company.business.aim.instance.Instance");
long hibernateId = ((Number) identifierGenerator.generate((SessionImplementor) session, null)).longValue();
For certain functionality in our application, an extremely large number (in the millions or 10s of millions) of entities are going to be generated. Benchmarking a pure JDBC approach versus JPA/Hibernate based approach shows the JDBC approach to be clearly the winner by a factor of 10 times faster than the JPA/Hibernate approach. However, in using pure JDBC for these millions of inserts, we would still like to use the identity generator that is configured via annotations, to generate the primary key values.
FWIW, the application is being designed to use JPA API and not Hibernate directly in most other areas.
Any pointers to concerns we should look out for will be highly appreciated.
Thanks in advance.