Bonjour,
je suis nouveau en hibernate, et je voudrais recuperer le dernier index inseré.
j'ai developpé cette methode:
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
25
26
27
28
29
30
31
32
33
34
35
36
public static int loadLastIndexInserted() throws Exception{
		Contact contact = new Contact();
		Session s = sf.openSession();
		Transaction tx = null;
		int idContact = 0;
		try {
			tx = s.beginTransaction();
			String SQL = "max(Contact.id) FROM Contact ";
			//Query query = s.createQuery (SQL);
			idContact = (Integer)s.createQuery(SQL.toString()).uniqueResult ();//<--
 
			tx.commit();
		}
		catch(Exception e) {
			if(tx!=null) {
				try {
					tx.rollback();
				}
				catch(HibernateException he) {
					throw he;
				}
			}
			throw e;
		}
		finally {
			try {
				s.disconnect();
				s.close();
			}
			catch(HibernateException ex) {
				throw new Exception(ex);
			}
		}
 
		 return idContact;
	}
mon probleme est dans la ligne avec la flêche <--.
veuillez m'aider pour resoudre mon probleme soit avec une correction de mon code soit avec une autre idée.
merci d'avance