Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 休眠缓存异常_Hibernate - Fatal编程技术网

Hibernate 休眠缓存异常

Hibernate 休眠缓存异常,hibernate,Hibernate,我尝试在hibernate的帮助下创建并填充数据库 我的Hibernate配置: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.d

我尝试在hibernate的帮助下创建并填充数据库

我的Hibernate配置:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
   "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
    <property name="connection.url">
        jdbc:h2:C:\Users\data\datastore
    </property>
    <property name="connection.username">admin</property>
    <property name="connection.password">admin</property>
    <property name="connection.driver_class">org.h2.Driver</property>
    <property name="dialect">org.hibernate.dialect.H2Dialect</property>
    <property name="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</property>
    <property name="current_session_context_class">thread</property>
    <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
    <property name="hibernate.hbm2ddl.auto">update</property>
    <mapping class="de.model.Player" />
    <mapping class="de.model.Team" />
    <mapping class="de.model.Goal" />
    <mapping class="de.model.Match" />
</session-factory>
我的主要意见是:

public class Main {
/**
 * 
 */
private static Logger log = Logger.getLogger(Main.class);
/**
 * 
 */
private static DAO dao = new DAO();
/**
 * 
 */
private static XMLReader reader = new XMLReader();

/**
 * 
 * @param args
 */
public static void main(String[] args) {
    try {
        Document allTeams = reader.parseFile("src/main/resources/teams.xml");
        Document allMatches = reader.parseFile("src/main/resources/matches.xml");

        List<Element> teams = allTeams.getRootElement().getChildren("Team");

        for(Element team: teams) {
            Team newTeam = new Team();
            newTeam.setId(Integer.parseInt(team.getChild("teamID").getValue()));
            newTeam.setName(team.getChild("teamName").getValue());
            newTeam.setIconUrl(team.getChild("teamIconURL").getValue());
            newTeam.setStadion(team.getChild("stadion").getValue());
            newTeam.setPlayer(new HashSet<Player>());

            List<Element> players = team.getChildren("player");

            for(Element player: players) {
                Player newPlayer = new Player();
                newPlayer.setName(player.getValue());
                newPlayer.setTeam(newTeam);

                newTeam.getPlayer().add(newPlayer);
            }

            dao.insertTeam(newTeam);

            for(Player player: newTeam.getPlayer()) {
                dao.insertPlayer(player);
            }
        }

        // dao.clean();
    } catch(RuntimeException e) {
        try {
            Session session = DBSessionHandler.getSessionFactoryInstance().getCurrentSession();

            if(session.getTransaction().isActive()) {
                session.getTransaction().rollback();
            }
        } catch(HibernateException e1) {
            log.error("Error rolling back transaction");
        }

        throw e;
    } catch (JDOMException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
}
我该如何解决这个问题?我是第一次尝试冬眠的 教程的帮助。在该教程中,它起到了作用^

尝试更改以下内容:

<property name="hibernate.cache.region.factory_class">
net.sf.ehcache.hibernate.EhCacheRegionFactory
</property>

net.sf.ehcache.hibernate.EhCacheRegionFactory


net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory
Exception in thread "main" org.hibernate.cache.CacheException:     net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM.  Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name.
<property name="hibernate.cache.region.factory_class">
net.sf.ehcache.hibernate.EhCacheRegionFactory
</property>
<property name="hibernate.cache.region.factory_class">
net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory
</property>