These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Base de données verrouillée en écriture
PostPosted: Mon Jun 11, 2007 5:21 am 
Newbie

Joined: Fri Jun 08, 2007 5:26 pm
Posts: 2
Bonjour,

Pendant l'exécution d'une appli web je dois remplacer la base de données gérée par Hibernate mais quand j'essaie de l'écraser par une autre base (sauvegarde) cela soulève une exception :


Code:
java.io.FileOutputStream.open(Native Method) java.io.FileOutputStream.<init>(Unknown Source) java.io.FileOutputStream.<init>(Unknown Source) util.Fichier.copieFichier(Fichier.java:103) pages.base.RestaurerAction.doRestaurer(RestaurerAction.java:62) pages.base.RestaurerAction.xExecute(RestaurerAction.java:32) pages.global.GlobalAction.execute(GlobalAction.java:66) ... 



En fait c'est Hibernate qui a mis un verrou sur le fichier base et tant que tomcat n'est pas arrêté le fichier ne peut pas être remplacé par un autre.

Pourtant dans mes requêtes j'ouvre mes sessions et les referme à chaque fois.

Voici un exemple :


Code:
public String getValeurParametre(String nom) throws Exception
{
  Session session = HibernateUtil.getSessionFactory().openSession();
  Parametre parametre = (Parametre) session.get(dao.Parametre.class, nom);
  session.close();
  return parametre != null ? parametre.getValeurPa() : null;
}

public void updateParametre(types.Parametre parametre) throws Exception
{
  Session session = HibernateUtil.getSessionFactory().openSession();
  Transaction tx = session.beginTransaction();
  try
  {
    session.update(parametre2ParametreBase(parametre)); tx.commit();
    session.close();
  }
  catch (Exception e)
  {
    tx.rollback();
    session.close();
    throw e;
  }




Comment donc dire à Hibernate de retirer ce verrou ?

Voici mon fichier HibernateUtil :

Code:
 
package dao.requete;
import org.hibernate.*;
import org.hibernate.cfg.*;

public class HibernateUtil
{
  private static final String HIBERNATE_FICHIER_CONFIGURATION = "hibernate.cfg.xml";
  private static SessionFactory sessionFactory;

  // public static final ThreadLocal session = new ThreadLocal();
 
public static SessionFactory getSessionFactory()
{
  return sessionFactory;
}

public static void init(String pathBase)
{
  Configuration cfg = new Configuration() .configure(HIBERNATE_FICHIER_CONFIGURATION);   
 
  cfg.setProperty("hibernate.connection.url", "jdbc:firebirdsql:localhost/3050:" + pathBase);
 
  cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.FirebirdDialect");
 
  cfg.setProperty("hibernate.cglib.use_reflection_optimizer", "false");
 
  cfg.setProperty("hibernate.connection.autocommit", "false");
 
  // cfg.setProperty("hibernate.transaction.auto_close_session", "true");         
 
  // Create the SessionFactory
  sessionFactory = cfg.buildSessionFactory();
  sessionFactory.openSession();
  }





Nota : Cette fonctionnalité avec JDBC seulement (et donc sans Hibernate + JDBC) fonctionne correctement.

Merci d'avance.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.