Jump to content

Problem with Second level caching in hibernate with ehcaching

So i am trying to use second level caching in hibernate using ehcache and this erro happened and i can't find particularly this error on any forum so can anyone help out pls. Thanks for help:

Hibernate.cfg.xml

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!-- JDBC Database connection settings -->
        <property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/Studentname?useSSL=false</property>
        <property name="connection.username">souranil</property>
        <property name="connection.password">soura21nil29</property>
        <property name="hbm2ddl.auto">update</property>
        <property name="hibernate.cache.use_second_level_cache">true</property>
        <property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.internal.EhcacheRegionFactory</property>
    </session-factory>
</hibernate-configuration>

The class that i am fetching data of from the database

package com.hibernate;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import jakarta.persistence.Cacheable;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToMany;

@Entity
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Subjects {
    @Id
    private int subjectcode;
    private String subjectname;
    @ManyToMany
    private List<Faculty> faculties=new ArrayList<Faculty>();
    // Faculty f1=new Faculty();
    public void setsubjectcode(int code){
        this.subjectcode=code;
    }
    public int getsubjectcode(){
        return subjectcode;
    }
    public void setsubjectname(String subjectname){
        this.subjectname=subjectname;
    }
    public String getsubjectname(){
        return subjectname;
    }
    public void setfaculties(ArrayList<Faculty> f1){
        this.faculties=f1;
    }
    public List<Faculty> getfaculties(){
        return this.faculties;
    }
    @Override
    public String toString() {
        String newlist=new String();
        for(int i=0;i<faculties.size();i++){
            newlist+=faculties.get(i).toString();
        }
        return "Subject code: "+subjectcode+"Subjectname: "+subjectname+"Faculties associated:\n"+newlist;
    }
}

The error:

image.thumb.png.71a5ae986ed599ca4a92e20a55e01d8c.png

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×