2014-04-24 3 views
0

Je sais que vous serez en colère contre moi. Mais je demanderai quand même. J'ai essayé toutes les solutions dans stackoverflow pour le problème. Mais non résolu. je produis hiberner dao POJO et hbm.xml.and lorsque je tente d'ajouter quelque chose avec dao, je reçois une erreur « Impossible de trouver SessionFactory JNDI ». ***Impossible de localiser SessionFactory dans JNDI

KullanicilarHome.java

public class KullanicilarHome { 

    private static final Log log = LogFactory.getLog(KullanicilarHome.class); 
    private final SessionFactory sessionFactory = getSessionFactory(); 

    protected SessionFactory getSessionFactory() { 
     try { 
      return (SessionFactory) new InitialContext() 
        .lookup("SessionFactory"); 
     } catch (Exception e) { 
      log.error("Could not locate SessionFactory in JNDI", e); 
      throw new IllegalStateException(
        "Could not locate SessionFactory in JNDI"); 
     } 
    } 

    public void persist(Kullanicilar transientInstance) { 
     log.debug("persisting Kullanicilar instance"); 
     try { 
      sessionFactory.getCurrentSession().persist(transientInstance); 
      log.debug("persist successful"); 
     } catch (RuntimeException re) { 
      log.error("persist failed", re); 
      throw re; 
     } 
    } 

et MainClass.java (test)

public class MainClass { 
    public static void main(String[] args) { 

     // TODO Auto-generated method stub 

     Kullanicilar user = new Kullanicilar(); 
     user.setAd("Ergin"); 
     user.setSoyad("DURAN"); 
     user.setUniversite("Kxxx"); 
     user.setBolum("bxx"); 
     user.setCepTel("5xxxxxx"); 
     user.setEmail("exxxx"); 
     user.setVeliTel("55xxxxx"); 
     KullanicilarHome x = new KullanicilarHome(); 
     x.persist(user); 

    } 

et hbm.cfg.xml

<hibernate-configuration> 
    <session-factory name="SessionFactory"> 
     <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 
     <property name="hibernate.connection.password">root</property> 
     <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/db</property> 
     <property name="hibernate.connection.username">root</property> 
     <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 
     <property name="hibernate.session_factory_name">SessionFactory</property> 
    </session-factory> 
</hibernate-configuration> 

et la version tomcat: v7.0.50 je le répète Avant de commencer à se mettre en colère. J'ai essayé toutes les solutions dans stackoverflow.but n'a pas fonctionné. ->enter link description here ->enter link description here ->enter link description here ->enter link description here

ont un même problème et là solutions ne m'a pas aidé ou ne comprenaient pas là des solutions. me aider .. s'il vous plaît je présente mes excuses pour mon mauvais anglais merci ***

Répondre

0

Je pense que vous êtes confus entre ejb et mise en veille prolongée, je ne vois pas où vous essayez de définir la SessionFactory dans JNDI. Vous devez effectuer les opérations suivantes

public class KullanicilarHome { 

private static final Log log = LogFactory.getLog(KullanicilarHome.class); 
private final SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); 
. 
. 
. 
. 

Remarque: Assurez-vous que le fichier .property figure dans le chemin d'accès aux classes. Habituellement, je le mets dans le dossier WEB-INF.

+0

Nous vous remercions de votre réponse. Je fais ce qu'ils disent.property et hbm.cfg.xml fichiers sur le même répertoire. src> main> java/MainClass & hibernate.properties & hibernate.cfg.xml et je reçois une erreur comme: http://codepaste.net/q3xyzt – erginduran

+0

Si je mets les fichiers (propriétés et HBM. cfg.xml) dans le web-inf, je reçois "hibernate.cfg.xml" erreur non trouvée – erginduran

+0

http://stackoverflow.com/questions/18736594/location-of-hibernate-cfg-xml-in-project – Zeus

Questions connexes