I am using Eclipse IDE 2022-6 for java programmers. I have installed Hibernate Tools for Eclipse Version: 5.4.16.v20220330-1129 and have in ClassPath Hibernate version 6.1.0.Final. Trying to set up a Java Hibernate annotation file for a H2 database and have problems finding to the needed library to be included in ClassPath.
In test program running:
// Create Session Factory
SessionFactory factory = new Configuration()
.configure(“hibernate.cfg.xml”)
.addAnnotatedClass(T131_Users.class)
.buildSessionFactory();
The line buildSessionFactory(); produce the following error message:
jun. 30, 2022 6:22:18 P.M. org.hibernate.Version logVersion
INFO: HHH000412: Hibernate ORM core version 6.1.0.Final
jun. 30, 2022 6:22:20 P.M. org.hibernate.spatial.integration.SpatialService
INFO: HHH80000001: hibernate-spatial integration enabled : true
jun. 30, 2022 6:22:20 P.M. org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using built-in connection pool (not intended for production use)
jun. 30, 2022 6:22:20 P.M. org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: Loaded JDBC driver class: org.h2.Driver
jun. 30, 2022 6:22:20 P.M. org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001012: Connecting with JDBC URL [jdbc:h2:file:C:/Users/nils/HRE/HibernateH2]
jun. 30, 2022 6:22:20 P.M. org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {password=****, user=SA}
jun. 30, 2022 6:22:20 P.M. org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
jun. 30, 2022 6:22:20 P.M. org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections
INFO: HHH10001115: Connection pool size: 1 (min=1)
jun. 30, 2022 6:22:20 P.M. org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl logSelectedDialect
INFO: HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
jun. 30, 2022 6:22:20 P.M. org.hibernate.envers.boot.internal.EnversServiceImpl configure
INFO: Envers integration enabled? : true
jun. 30, 2022 6:22:20 P.M. org.hibernate.spatial.dialect.h2gis.H2GisDialectContributor contributeJdbcTypes
INFO: HHH80000003: hibernate-spatial adding type contributions from : org.hibernate.spatial.dialect.h2gis.H2GisDialectContributor
jun. 30, 2022 6:22:21 P.M. org.hibernate.spatial.dialect.h2gis.H2GisDialectContributor contributeFunctions
INFO: HHH80000004: hibernate-spatial adding function contributions from : org.hibernate.spatial.dialect.h2gis.H2GisDialectContributor
jun. 30, 2022 6:22:21 P.M. org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator initiateService
INFO: HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
jun. 30, 2022 6:22:21 P.M. org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PoolState stop
INFO: HHH10001008: Cleaning up connection pool [jdbc:h2:file:C:/Users/nils/HRE/HibernateH2]
Exception in thread “main” org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jndi.spi.JndiService]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:267)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:230)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:207)
at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.getService(SessionFactoryServiceRegistryImpl.java:100)
at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:388)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:415)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:754)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:773)
at hre.hibernate.test.HibernateTestHRE.main(HibernateTestHRE.java:27)
Caused by: java.lang.StringIndexOutOfBoundsException: begin 15, end 14, length 14
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4604)
at java.base/java.lang.String.substring(String.java:2707)
at java.base/java.lang.String.substring(String.java:2680)
at org.hibernate.engine.jndi.internal.JndiServiceImpl.extractJndiProperties(JndiServiceImpl.java:82)
at org.hibernate.engine.jndi.internal.JndiServiceImpl.(JndiServiceImpl.java:49)
at org.hibernate.engine.jndi.internal.JndiServiceInitiator.initiateService(JndiServiceInitiator.java:33)
at org.hibernate.engine.jndi.internal.JndiServiceInitiator.initiateService(JndiServiceInitiator.java:20)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:119)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:255)
… 8 more
Create newUser object!!
Begin save user object!!
Exception: Unable to locate persister: hre.hibernate.annotation.T131_Users
java.lang.IllegalArgumentException: Unable to locate persister: hre.hibernate.annotation.T131_Users
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:736)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:717)
at hre.hibernate.test.HibernateTestHRE.main(HibernateTestHRE.java:45)
The test program looks like this:
package hre.hibernate.test;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import hre.hibernate.annotation.T131_Users;
public class HibernateTestHRE {
public HibernateTestHRE() {
}
public static void main(String[] args) {
// Create Session Factory
SessionFactory factory = new Configuration()
.configure("hibernate.cfg.xml")
.addAnnotatedClass(T131_Users.class)
.buildSessionFactory();
// Create Session
//Session session = factory.getCurrentSession();
Session session = factory.openSession();
try {
// Create a user object
System.out.println("Create newUser object!!");
T131_Users newUser = new T131_Users("NTo","Nils Tolleshaug","HRE-2021","nils@tolleshug.net");
// Start a transaction
session.beginTransaction();
//Save the user Object
System.out.println("Begin save user object!!");
session.persist(newUser);
//session.save(newUser);
// Commit transaction
Transaction transaction = session.beginTransaction();
transaction.commit();
System.out.println("Done save user!!");
} catch (Exception exc) {
System.out.println("Exception: " + exc.getMessage());
exc.printStackTrace();
} finally {
factory.close();
}
}
}
The problem is now in: session.persist(newUser);
Maybe this is related to hibernate 6.0 that use ‘jakarta.persistence’
insted of javax.persistence.
What ‘jakarta lib’ version is now needed for hibernate 6.0 ?