Bonjour,

lorsque j'essaie d'inserer des données :

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
 public static void main(String[] args) throws HibernateException {
 
	 Session session = HibernateUtil.currentSession();
	 //Transaction tx = session.beginTransaction();
 
 
	 //Insertion 
	 User u = new User();
	 u.setNom("che");
	 u.setPrenom("Sylvie");
	 session.save(u);
 
 
	 tx.commit();
	 HibernateUtil.closeSession();
 }
}
ou je fais une mise à jour :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
public static void main(String[] args) throws HibernateException {
 
	 Session session = HibernateUtil.currentSession();
	 Transaction tx = session.beginTransaction();
 
	 User u = (User) session.load(User.class, new Integer(1));
	 u.setPrenom("Jacques");
	 session.save(u);
 
 
	 tx.commit();
	 HibernateUtil.closeSession();
 }
}
ca passe nickel. Mais quand j'essaie de lire le contenu de ma table user (que j'ai renommé en tuser par la suite car je me suis dit que peut etre que c'est un mot reservé).



Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
	 Query query = session.createQuery("from tuser");
	 List list = query.list();
	 //List list = session.find("from user");
	 Iterator it = list.iterator();
	 while (it.hasNext()) {
		 User u = (User)it.next();
		 System.out.print(u.getPrenom());
	 }

j'ai a chaque fois une erreur com.mysql.jdbc.exceptions.MySQLSyntaxErrorException qui me dit que me requete n'est HQL n'est pas correct. Je ne comprends pas, comment peux t-on faire plus simple qu'un : from Matable

Ou me suis je trompé ?

INFO: building session factory
22 juin 2008 11:29:12 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
22 juin 2008 11:29:12 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
ATTENTION: SQL Error: 1064, SQLState: 42000
22 juin 2008 11:29:12 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
GRAVE: Erreur de syntaxe près de 'from' à la ligne 1
22 juin 2008 11:29:12 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
ATTENTION: SQL Error: 1064, SQLState: 42000
22 juin 2008 11:29:12 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
GRAVE: Erreur de syntaxe près de 'from' à la ligne 1
22 juin 2008 11:29:12 net.sf.hibernate.JDBCException <init>
GRAVE: Could not execute query
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Erreur de syntaxe près de 'from' à la ligne 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1467)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at Test.main(Test.java:28)
Exception in thread "main" net.sf.hibernate.JDBCException: Could not execute query
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1547)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at Test.main(Test.java:28)
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Erreur de syntaxe près de 'from' à la ligne 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1467)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
... 2 more
PS : je me suis inspiré du tuto : http://defaut.developpez.com/tutorie...pse/hibernate/