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.  [ 4 posts ] 
Author Message
 Post subject: premiere essai d'hibernate
PostPosted: Sun Apr 23, 2006 2:51 pm 
Newbie

Joined: Sun Apr 23, 2006 2:24 pm
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

hibernate 3.1.1 + hibernatesynchronizer 3.1.1

// Récupération de la session :
Session session = HibernateUtil.currentSession();
// Début d'une transaction :
Transaction transaction = session.beginTransaction();
/*** TEST D'INSERTION ***/

User user = new User();
user.setLogin("FORET");
user.setPassword("marie");
session.save(user);

// Validation de la transaction :
transaction.commit();
HibernateUtil.closeSession();


23 avr. 2006 18:43:27 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.1.1
23 avr. 2006 18:43:27 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
23 avr. 2006 18:43:27 org.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
23 avr. 2006 18:43:27 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
23 avr. 2006 18:43:27 org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
23 avr. 2006 18:43:27 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
23 avr. 2006 18:43:27 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource: User.hbm.xml
23 avr. 2006 18:43:27 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: table.User -> user
23 avr. 2006 18:43:27 org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
23 avr. 2006 18:43:27 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
23 avr. 2006 18:43:27 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
23 avr. 2006 18:43:27 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
23 avr. 2006 18:43:27 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost:3306/exemple_hibernate
23 avr. 2006 18:43:27 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=root, password=****}
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: MySQL, version: 5.0.17-nt
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.6 ( $Date: 2004/12/09 15:57:25 $, $Revision: 1.27.4.52 $ )
23 avr. 2006 18:43:28 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
23 avr. 2006 18:43:28 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
23 avr. 2006 18:43:28 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
23 avr. 2006 18:43:28 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.EhCacheProvider
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
23 avr. 2006 18:43:28 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
23 avr. 2006 18:43:28 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
23 avr. 2006 18:43:28 net.sf.ehcache.config.Configurator configure
ATTENTION: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Documents%20and%20Settings/eharel/workspace/essai_tomcat/WEB-INF/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
23 avr. 2006 18:43:29 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Enregistrement réussi !


MySQL 5.0

Je débute avec hibernate et là j'avoue être un peu perdu. J'utilise Eclipse 3.1 j'ai crée une base et table de la facon suivante :

CREATE TABLE user(
id INT AUTO_INCREMENT PRIMARY KEY,
login VARCHAR(20),
password VARCHAR(20)
);

je voudrais donc remplir cette table par hibernate et faire persister un type User
Tout d'abord je ne sais pas si je dois lancer le serveur tomcat sous Eclipse (avec sysdeo) ou bien cela n'est pas nécessaire ?

Voyez vous d'ou peut bien venir l'erreur ?
Merci


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 24, 2006 11:04 am 
Regular
Regular

Joined: Sat May 15, 2004 4:27 am
Posts: 79
Heeuu... Dans tes logs je vois beaucoup d'INFO mais pas d'erreur ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 25, 2006 12:59 pm 
Newbie

Joined: Sun Apr 23, 2006 2:24 pm
Posts: 3
Pas d'erreur ???
mais pourquoi alors est ce que ces lignes s'affichent dans ma console d'eclipse ?
De plus ces qq lignes de codes ne font pas ce qu'elles doivent faire c'est a dire ajouter en base un nouvelle User.
Quelqu'un a t il une idée svp
Merci


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 06, 2006 9:29 am 
Newbie

Joined: Sun Apr 23, 2006 2:24 pm
Posts: 3
Rebonjour,


Je n'ai toujours pas resolu mon probleme

Jutilise Eclipse 3.1.1, tomcat 5.0, JAVA 1.5
Le code très simple pourtant :

import java.util.*;
import org.hibernate.*;
import util.*;
import table.User;

public class Test {

/**
* @param args
*/
public static void main(String[] args) throws HibernateException
{


Session session = HibernateUtil.currentSession();

// Début d'une transaction :
Transaction transaction = session.beginTransaction();

/*** TEST D'INSERTION ***/
/*
User user = new User();
user.setLogin("LAFORET");
user.setPassword("marie");
session.save(user);
*/

/*** TEST DE MISE A JOUR ***/
/*
User user = (User)session.load(User.class,new Integer(1));
user.setLogin("TOTO");
*/

/*** TEST DE LECTURE ***/

//List contacts = session.createQuery("from User where login like '%H'").list();
Iterator iterator = contacts.iterator();

while(iterator.hasNext())
{
User userResult =(User)iterator.next();
System.out.println("Login : "+userResult.getLogin()
+ " Password : "+userResult.getPassword() );
}

// Validation de la transaction :
transaction.commit();
HibernateUtil.closeSession();

}// main

}// classe Test


Je crée un projet tomcat et lorsque je lance j'obtiens dans la console eclipse :

ATTENTION: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Documents%20and%20Settings/mister/workspace/essai_tomcat/WEB-INF/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
6 mai 2006 15:25:24 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Exception in thread "main" java.lang.NoClassDefFoundError: antlr/ANTLRException
at org.hibernate.hql.ast.ASTQueryTranslatorFactory.createQueryTranslator(ASTQueryTranslatorFactory.java:31)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:72)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:134)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:113)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1600)
at Test.main(Test.java:38)

S'il vous plait je pensais que c'etait pourtant simple hibernate.


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

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.