IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Hibernate Java Discussion :

problème configuration hibernate avec bdd mysql, tomcat et eclipse


Sujet :

Hibernate Java

  1. #1
    Futur Membre du Club
    Inscrit en
    Février 2007
    Messages
    25
    Détails du profil
    Informations forums :
    Inscription : Février 2007
    Messages : 25
    Points : 8
    Points
    8
    Par défaut problème configuration hibernate avec bdd mysql, tomcat et eclipse
    Bonjour,

    Je suis débutant en programmation web, et j'ai un serieux problème avec hibernate, j'ai deja un code source d'un projet qui a ete concu et qui marche sous serveur sun, sauf que moi je veux l'utiliser avec tomcat 6.0.
    il y a des pages qui s'execute, là ou il ya que de l'interface, par contre dès qu'il y a apel à hibernate, ca foire:

    J'ai suivi un tutorial pour configurer hibernate avec le plugin hibernate tools, ca gènere hibernate.cfg.xml avec les mapp et ses .java

    Par contre dès qu'une page fait apel à hibernate j'ai ca:

    GRAVE: "Servlet.service()" pour la servlet jsp a lancé une exception
    java.lang.NoClassDefFoundError: Could not initialize class siroco.service.HibernateUtil


    Je croit que j'ai mis tout les jar necessaire dans le lib du projet.

    Qu'est ce que je doit faire, ca fait 3 jours que je suis bloqué dessus??

    Merci d'avance

  2. #2
    Membre habitué Avatar de we.are.the.storm
    Profil pro
    Inscrit en
    Février 2009
    Messages
    115
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Février 2009
    Messages : 115
    Points : 139
    Points
    139
    Par défaut
    Bonjour,

    La classe siroco.service.HibernateUtil n'existe pas.
    Rajoute cette classe dans tes sources Java dans le package siroco.service:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
     
    import org.hibernate.*;
    import org.hibernate.cfg.*;
     
    public class HibernateUtil {
     
        private static final SessionFactory sessionFactory;
     
        static {
            try {
                // Create the SessionFactory from hibernate.cfg.xml
                sessionFactory = new Configuration().configure().buildSessionFactory();
            } catch (Throwable ex) {
                // Make sure you log the exception, as it might be swallowed
                System.err.println("Initial SessionFactory creation failed." + ex);
                throw new ExceptionInInitializerError(ex);
            }
        }
     
        public static SessionFactory getSessionFactory() {
            return sessionFactory;
        }
     
    }

  3. #3
    Futur Membre du Club
    Inscrit en
    Février 2007
    Messages
    25
    Détails du profil
    Informations forums :
    Inscription : Février 2007
    Messages : 25
    Points : 8
    Points
    8
    Par défaut
    si si elle existe voila et ca compile bien, voila son code:

    package siroco.service;

    import java.util.Iterator;

    import org.hibernate.HibernateException;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.Transaction;
    import org.hibernate.cfg.AnnotationConfiguration;
    import org.hibernate.cfg.Configuration;
    import org.hibernate.mapping.PersistentClass;
    import org.hibernate.tool.hbm2ddl.SchemaExport;


    public class HibernateUtil
    {
    private static final SessionFactory _sessionFactory;
    static
    {
    // _sessionFactory = new
    // Configuration().configure().buildSessionFactory();
    Configuration config = new AnnotationConfiguration().configure();

    // Don't make the class "lazy" (this is not yet possible in annotations)
    for (Iterator it = config.getClassMappings(); it.hasNext()
    {
    PersistentClass p = (PersistentClass) it.next();
    p.setProxyInterfaceName(null);
    }
    _sessionFactory = config.buildSessionFactory();

    /* désactivation de la création de la base de données à partir des classes du domaine
    SchemaExport exp = new SchemaExport(config);
    exp.setOutputFile("createDatabase_deduced.sql");
    exp.create(true, true);
    */
    }

    public static final ThreadLocal<Session> _session = new ThreadLocal<Session>();
    public static final ThreadLocal<Transaction> _tx = new ThreadLocal<Transaction>();

    // Session management
    public static boolean isSessionOpen() throws HibernateException
    {
    return _session.get() != null;
    }


    public static Session openSession() throws HibernateException
    {
    Session s = getCurrentSession();
    if (s == null)
    {
    s = _sessionFactory.openSession();
    _session.set(s);
    _tx.set(null);
    }
    else
    {
    throw new RuntimeException("Session was already open");
    }
    return s;
    }


    public static Session getCurrentSession() throws HibernateException
    {
    return _session.get();
    }


    public static void closeSession() throws HibernateException
    {
    Session s = getCurrentSession();
    if (s != null)
    {
    _session.set(null);
    _tx.set(null);
    s.close();
    }
    else
    {
    throw new RuntimeException("Session was not open");
    }
    }


    // Transaction management
    public static Transaction beginTransactionOrEnlist() throws HibernateException
    {
    Transaction result = getCurrentTransaction();
    if (result == null)
    {
    Session s = getCurrentSession();
    if (s != null)
    {
    result = s.beginTransaction();
    _tx.set(result);
    }
    else
    {
    throw new RuntimeException("Session was not open");
    }
    }
    return result;
    }


    public static Transaction getCurrentTransaction() throws HibernateException
    {
    return _tx.get();
    }


    public static void commitTransactionIfOpen() throws HibernateException
    {
    Transaction tx = getCurrentTransaction();
    if (tx != null)
    {
    _tx.set(null);
    tx.commit();
    }
    }


    public static void rollbackTransactionIfOpen() throws HibernateException
    {
    Transaction tx = getCurrentTransaction();
    if (tx != null)
    {
    _tx.set(null);
    tx.rollback();
    }
    }
    }


    je comprend pas pk ca marche pas, le problème c'est que ca marchait avec le serveur sun, et quand je suis passer à tomcat j'ai eu ce problème, mais attendez, la serice sur le gateau, quand je suis revenu sur le serveur sun, et ben il me genere la meme erreur

    javax.servlet.ServletException: java.lang.NoClassDefFoundError: Could not initialize class siroco.service.HibernateUtil


  4. #4
    Membre à l'essai
    Inscrit en
    Décembre 2009
    Messages
    11
    Détails du profil
    Informations forums :
    Inscription : Décembre 2009
    Messages : 11
    Points : 13
    Points
    13
    Par défaut
    j'ai ce msg d'erreur:


    24 mars 2010 14:47:37 net.sf.hibernate.cfg.Environment <clinit>
    INFO: Hibernate 2.1.6
    24 mars 2010 14:47:37 net.sf.hibernate.cfg.Environment <clinit>
    INFO: hibernate.properties not found
    24 mars 2010 14:47:37 net.sf.hibernate.cfg.Environment <clinit>
    INFO: using CGLIB reflection optimizer
    24 mars 2010 14:47:37 net.sf.hibernate.cfg.Configuration configure
    INFO: configuring from resource: /hibernate.cfg.xml
    24 mars 2010 14:47:37 net.sf.hibernate.cfg.Configuration getConfigurationInputStream
    INFO: Configuration resource: /hibernate.cfg.xml
    24 mars 2010 14:47:37 net.sf.hibernate.cfg.Configuration addResource
    INFO: Mapping resource: TContact.hbm
    24 mars 2010 14:47:37 net.sf.hibernate.cfg.Binder bindRootClass
    INFO: Mapping class: com.minosis.hibernate.TContact -> t_contact
    24 mars 2010 14:47:37 net.sf.hibernate.cfg.Configuration doConfigure
    INFO: Configured SessionFactory: null
    24 mars 2010 14:47:37 net.sf.hibernate.cfg.Configuration secondPassCompile
    INFO: processing one-to-many association mappings
    24 mars 2010 14:47:37 net.sf.hibernate.cfg.Configuration secondPassCompile
    INFO: processing one-to-one association property references
    24 mars 2010 14:47:37 net.sf.hibernate.cfg.Configuration secondPassCompile
    INFO: processing foreign key constraints
    24 mars 2010 14:47:37 net.sf.hibernate.dialect.Dialect <init>
    INFO: Using dialect: net.sf.hibernate.dialect.PostgreSQLDialect
    24 mars 2010 14:47:37 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: Use outer join fetching: true
    24 mars 2010 14:47:37 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: Using Hibernate built-in connection pool (not for production use!)
    24 mars 2010 14:47:37 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: Hibernate connection pool size: 10
    24 mars 2010 14:47:37 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: using driver: org.postgresql.Driver at URL: jdbc:postgresql://127.0.0.1:5432/test_bd
    24 mars 2010 14:47:37 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: connection properties: {user=postgres, password=postgres}
    24 mars 2010 14:47:37 net.sf.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
    INFO: Transaction strategy: net.sf.hibernate.transaction.JDBCTransactionFactory
    24 mars 2010 14:47:37 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
    INFO: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
    24 mars 2010 14:47:38 net.sf.hibernate.cfg.SettingsFactory buildSettings
    ATTENTION: Could not obtain connection metadata
    org.postgresql.util.PSQLException: La tentative de connexion a échoué.
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:136)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:65)
    at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:116)
    at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
    at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24)
    at org.postgresql.Driver.makeConnection(Driver.java:369)
    at org.postgresql.Driver.connect(Driver.java:245)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:101)
    at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:73)
    at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1155)
    at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:789)
    at com.minosis.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:11)
    at Test.main(Test.java:8)
    Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(Unknown Source)
    at java.io.BufferedInputStream.fill(Unknown Source)
    at java.io.BufferedInputStream.read(Unknown Source)
    at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:256)
    at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:253)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:94)
    ... 14 more
    24 mars 2010 14:47:38 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: Use scrollable result sets: false
    24 mars 2010 14:47:38 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: Use JDBC3 getGeneratedKeys(): false
    24 mars 2010 14:47:38 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: Optimize cache for minimal puts: false
    24 mars 2010 14:47:38 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: echoing all SQL to stdout
    24 mars 2010 14:47:38 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: Query language substitutions: {}
    24 mars 2010 14:47:38 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: cache provider: net.sf.hibernate.cache.EhCacheProvider
    24 mars 2010 14:47:38 net.sf.hibernate.cfg.Configuration configureCaches
    INFO: instantiating and configuring caches
    Exception in thread "main" java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V
    at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:47)
    at net.sf.cglib.core.DefaultGeneratorStrategy.getClassWriter(DefaultGeneratorStrategy.java:30)
    at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)
    at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:215)
    at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
    at net.sf.hibernate.impl.SessionFactoryImpl.<clinit>(SessionFactoryImpl.java:236)
    at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:791)
    at com.minosis.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:11)
    at Test.main(Test.java:8)




    voila mon fichier de configuration:

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-configuration
    PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

    <hibernate-configuration>
    <session-factory >

    <!-- local connection properties -->
    <property name="hibernate.connection.url">jdbc:postgresql://127.0.0.1:5432/test_bd</property>
    <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
    <property name="hibernate.connection.username">postgres</property>
    <property name="hibernate.connection.password">postgres</property>
    <!-- property name="hibernate.connection.pool_size"></property -->

    <!-- dialect for PostgreSQL -->
    <property name="dialect">net.sf.hibernate.dialect.PostgreSQLDialect</property>

    <property name="hibernate.show_sql">false</property>
    <property name="hibernate.use_outer_join">true</property>
    <property name="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>
    <property name="jta.UserTransaction">java:comp/UserTransaction</property>

    </session-factory>
    </hibernate-configuration>

    voila la classe: HibernateUtil.java


    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-configuration
    PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

    <hibernate-configuration>
    <session-factory >

    <!-- local connection properties -->
    <property name="hibernate.connection.url">jdbc:postgresql://127.0.0.1:5432/test_bd</property>
    <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
    <property name="hibernate.connection.username">postgres</property>
    <property name="hibernate.connection.password">postgres</property>
    <!-- property name="hibernate.connection.pool_size"></property -->

    <!-- dialect for PostgreSQL -->
    <property name="dialect">net.sf.hibernate.dialect.PostgreSQLDialect</property>

    <property name="hibernate.show_sql">false</property>
    <property name="hibernate.use_outer_join">true</property>
    <property name="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>
    <property name="jta.UserTransaction">java:comp/UserTransaction</property>

    </session-factory>
    </hibernate-configuration>



    j'utilise eclipse
    postgresql 8.3
    hibernate synchronizer

    pllllzzzzz aider mois.merci.

Discussions similaires

  1. [MySQL] problème d'affichage dans tableau avec bdd Mysql
    Par sinifer dans le forum PHP & Base de données
    Réponses: 5
    Dernier message: 01/05/2009, 10h50
  2. Réponses: 10
    Dernier message: 25/02/2009, 17h34
  3. Problème cache hibernate avec MySQL
    Par bierfoot dans le forum Hibernate
    Réponses: 0
    Dernier message: 14/01/2009, 15h51
  4. [C#]Problème OleDbCommand.ExecuteReader avec BdD Access
    Par Renesis57 dans le forum Windows Forms
    Réponses: 2
    Dernier message: 24/09/2006, 19h36
  5. Problème cases à cocher avec connection Mysql
    Par cams dans le forum SQL Procédural
    Réponses: 8
    Dernier message: 01/12/2005, 15h13

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo