# Library for Eclipse H2 development

**URL:** <https://discourse.hibernate.org/t/library-for-eclipse-h2-development/6446>\
**Category:** Hibernate ORM\
**Created:** [June 30, 2022, 5:54pm UTC](https://discourse.hibernate.org/t/library-for-eclipse-h2-development/6446 "2022-06-30T17:54:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nils\_Tolleshaug](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/nils_tolleshaug/32/1937_2.png) [@Nils\_Tolleshaug](https://discourse.hibernate.org/u/Nils_Tolleshaug)\
**Post date:** [June 30, 2022, 5:54pm UTC](https://discourse.hibernate.org/t/library-for-eclipse-h2-development/6446/1 "2022-06-30T17:54:27Z")

</div>

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

Any advice appreciated

Nils

---

<div class="post-metadata">

**Author:** ![dreab8](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/dreab8/32/25_2.png) [@dreab8](https://discourse.hibernate.org/u/dreab8)\
**Post date:** [July 1, 2022, 10:28am UTC](https://discourse.hibernate.org/t/library-for-eclipse-h2-development/6446/2 "2022-07-01T10:28:08Z")

</div>

> [@Nils\_Tolleshaug](#):
>
> extractJndiProperties

Hi @Nils_Tolleshaug ,

Can you pleas provide the content of the `hibernate.cfg.xml` file?

---

<div class="post-metadata">

**Author:** ![Nils\_Tolleshaug](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/nils_tolleshaug/32/1937_2.png) [@Nils\_Tolleshaug](https://discourse.hibernate.org/u/Nils_Tolleshaug)\
**Post date:** [July 1, 2022, 10:41am UTC](https://discourse.hibernate.org/t/library-for-eclipse-h2-development/6446/3 "2022-07-01T10:41:28Z")

</div>

Thanks for the answer and my intention was to include, but had problems with editor.  
The hibernate.cfg.xml:

\<?xml version="1.0" encoding="UTF-8"?\> org.h2.Driver jdbc:h2:file:C:/Users/nils/HRE/HibernateH2 SA http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd org.hibernate.dialect.H2Dialect 1 hre.hibernate.annotation.T131\_Users HRE-Annotation 

I suspect I have a problem with the “hibernate.jndi” setting?

```auto
Here is also the Java annotation file:
package hre.hibernate.annotation;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.antlr.v4.runtime.misc.NotNull;

/**
 * @author NTo
 * CREATE TABLE T131_USERS(
	PID BIGINT NOT NULL,
	CL_COMMIT_RPID BIGINT NOT NULL,
	LOGON_NAME VARCHAR(100) NOT NULL,
	USER_NAME VARCHAR(100) NOT NULL,
	PASSWORD VARCHAR(100) NOT NULL,
	EMAIL VARCHAR(100) NOT NULL,
	USER_GROUP_RPID BIGINT NOT NULL
	);
 */
@Entity
@Table(name="T131_USERS")
public class T131_Users {
	
    long proOffset = 1000000000000000L;
    long null_RPID = 1999999999999999L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="PID")
	@NotNull
	private long pid;
	
	@Column(name="CL_COMMIT_RPID")
	@NotNull
	private long clCommit;
	
	@Column(name="LOGON_NAME")
	@NotNull
	private String logonName;
	
	@Column(name="USER_NAME")
	@NotNull
	private String userName;
	
	@Column(name="PASSWORD")
	@NotNull
	private String password;
	
	@Column(name="EMAIL")
	@NotNull
	private String email;
	
	@Column(name="USER_GROUP_RPID")
	@NotNull
	private long userGroupRPID;
	
	public T131_Users() {
		System.out.println("T131_Users constructor");
	}

	public T131_Users(String logonName, String userName, String password, String email) {
		//super();
		this.clCommit = null_RPID;
		this.logonName = logonName;
		this.userName = userName;
		this.password = password;
		this.email = email;
		this.userGroupRPID = null_RPID;
		
	}

	public long getPid() {
		return pid;
	}

	public void setPid(long pid) {
		this.pid = pid;
	}

	public long getClCommit() {
		return clCommit;
	}

	public void setClCommit(long clCommit) {
		this.clCommit = clCommit;
	}

	public String getLogonName() {
		return logonName;
	}

	public void setLogonName(String logonName) {
		this.logonName = logonName;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public long getUserGroupRPID() {
		return userGroupRPID;
	}

	public void setUserGroupRPID(long userGroupRPID) {
		this.userGroupRPID = userGroupRPID;
	}

	@Override
	public String toString() {
		return "T131_Users [pid=" + pid + ", clCommit=" + clCommit + ", logonName=" + logonName + ", userName="
				+ userName + ", password=" + password + ", email=" + email + ", userGroupRPID=" + userGroupRPID + "]";
	}
}

```

Thanks for assistance!  
Nils

---

<div class="post-metadata">

**Author:** ![Nils\_Tolleshaug](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/nils_tolleshaug/32/1937_2.png) [@Nils\_Tolleshaug](https://discourse.hibernate.org/u/Nils_Tolleshaug)\
**Post date:** [July 1, 2022, 10:45am UTC](https://discourse.hibernate.org/t/library-for-eclipse-h2-development/6446/4 "2022-07-01T10:45:03Z")

</div>

No success with hibernate.cfg.xml:

```auto
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                         "https://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory name="HRE-Hibernate">
  <property name="hibernate.connection.driver_class">org.h2.Driver</property>
  <property name="hibernate.connection.url">jdbc:h2:file:C:/Users/nils/HRE/HibernateH2</property>
  <property name="hibernate.connection.username">SA</property>
  <property name="hibernate.default_schema">http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd</property>
  <property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
  <property name="hibernate.connection.password"/>
  <property name="hibernate.connection.pool_size">1</property>
  <property name="hibernate.jndi.class">hre.hibernate.annotation.T131_Users</property>
  <property name="hibernate.jndi">HRE-Annotation</property>
 </session-factory>
</hibernate-configuration>

```

I suspect I have a problem with the “hibernate.jndi” setting?

Any advice appreciated.

Rgs Nils

---

<div class="post-metadata">

**Author:** ![dreab8](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/dreab8/32/25_2.png) [@dreab8](https://discourse.hibernate.org/u/dreab8)\
**Post date:** [July 1, 2022, 11:17am UTC](https://discourse.hibernate.org/t/library-for-eclipse-h2-development/6446/5 "2022-07-01T11:17:00Z")

</div>

> [@Nils\_Tolleshaug](#):
>
> `hibernate.jndi.class`

not sure why you want to specify a `hibernate.jndi.class` but as specified in the doc [8. JNDI | hibernate](https://quizix.gitbooks.io/hibernate/content/hibernate_user_guide/8_jndi.html) it should name the javax.naming.InitialContext implementation class to use. See [`javax.naming.Context#INITIAL_CONTEXT_FACTORY`](https://docs.oracle.com/javase/8/docs/api/javax/naming/Context.html#INITIAL_CONTEXT_FACTORY)

---

<div class="post-metadata">

**Author:** ![Nils\_Tolleshaug](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/nils_tolleshaug/32/1937_2.png) [@Nils\_Tolleshaug](https://discourse.hibernate.org/u/Nils_Tolleshaug)\
**Post date:** [July 1, 2022, 4:34pm UTC](https://discourse.hibernate.org/t/library-for-eclipse-h2-development/6446/6 "2022-07-01T16:34:02Z")

</div>

Thanks!  
It was not my intention to specify hibernate.jndi.class and the following hibernate config worked:

```auto
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                         "https://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory>
  <property name="hibernate.connection.driver_class">org.h2.Driver</property>
  <property name="hibernate.connection.url">jdbc:h2:file:C:/Users/nils/HRE/HibernateH2</property>
  <property name="hibernate.connection.username">SA</property>
  <property name="hibernate.default_schema">http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd</property>
  <property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
  <property name="hibernate.connection.password"/>
  <property name="hibernate.connection.pool_size">1</property>
  <property name="hibernate.jndi.class"></property>
 </session-factory>
</hibernate-configuration>

```

Now I have a new problem in the test setup:

```auto
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:

```auto
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 ?

Your help is highly appreciated.  
Rgs Nils

---

<div class="post-metadata">

**Author:** ![dreab8](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/dreab8/32/25_2.png) [@dreab8](https://discourse.hibernate.org/u/dreab8)\
**Post date:** [July 14, 2022, 7:05am UTC](https://discourse.hibernate.org/t/library-for-eclipse-h2-development/6446/7 "2022-07-14T07:05:02Z")

</div>

Hibernate 6 is using Jakarta 3.0
