I am trying to learn Hibernate and while follwing the tuterial the second level cache he is using is not working any more and when trying to find options I could not get to a solutions here is what my POM.xml file looks like
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hubernatefirstproject</groupId>
<artifactId>HibernateProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>HibernateProject</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.3.1.Final</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.sf.ehcache/ehcache -->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.10.9.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jcache</artifactId>
<version>5.6.10.Final</version>
</dependency>
<!-- <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>5.6.15.Final</version>
</dependency>-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<!--<scope>test</scope>-->
</dependency>
</dependencies>
</project>
and here is what my hibermnate.cfg.xml lokks like
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/Engineers</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">Pro@admin123</property>
<!--<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>-->
<property name="hbm2ddl.auto">update</property>
<property name="show_sql">true</property>
<!--Second level caching configure-->
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.query_cache_factory">org.hibernate.cache.jcache.internal.JCacheRegionFactory</property>
</session-factory>
</hibernate-configuration>
and here is my Entity Class
import jakarta.persistence.*;
import org.hibernate.annotations.CacheConcurrencyStrategy;
@Entity
@Cacheable
@org.hibernate.annotations.Cache(usage= CacheConcurrencyStrategy.READ_ONLY)
public class Student {
@Id
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
and my main class
Configuration con = new Configuration().configure().addAnnotatedClass(Student.class);
ServiceRegistry reg = new StandardServiceRegistryBuilder().applySettings(con.getProperties()).build();
SessionFactory sf = con.buildSessionFactory(reg);
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
alien = (Student) session.get(Alien.class, 101);
System.out.println(student);
session.getTransaction().commit();
session.close();
Session session2 = sf.openSession();
session2.beginTransaction();
student = (Student) session2.get(Student.class, 101);
System.out.println(student);
session2.getTransaction().commit();
Can anyone help me with that dependency what is the right way of puting the property on hibernate cfg file
I really appreciate you time and effort
I have tried on the property with provider and the xml file and the region factory_class is not even coming as an option and not sure if I even be able to get it from the jcache, also innitially I was starting with the hibernate-ehcache dependency but on that I was getting error the @Cache(usage=…) Cache was not even compiling