Salut la compagnie !

Aujourd'hui dans la série problème à deux balles je vous présente le nouveau venu.

Ma MOA m'a demandé de faire un fichier Excel depuis mon IHM. Pour faire à la volée sur mon appli web je créé depuis un lien une popup qui ouvre un nouveau formulaire Strus afin d'écrire directement dans le

Code : Sélectionner tout - Visualiser dans une fenêtre à part
response.getOutputStream();
Mes données Excel.

Je m'en sors à merveille jusque ce que Oracle me fasse la gueule, comme quoi gnagnagna j'ai 30 connexion en cours...



Oula y a comme un hic.

Et oui à chaque popup j'aurai une dupplication de connexion.

Là je comprend pas...

Mon hibernateUtils est tiré du site officiel :

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
public class HibernateUtil {
	private static SessionFactory sessionFactory;
 
	private static Configuration configuration;
 
	static {
		// Create the initial SessionFactory from the default configuration
		// files
		try {
			// Read hibernate.properties, if present
			configuration = new Configuration();
			// Use annotations: configuration = new AnnotationConfiguration();
 
			// Read hibernate.cfg.xml (has to be present)
			configuration.configure();
 
			// Build and store (either in JNDI or static variable)
			rebuildSessionFactory(configuration);
 
		} catch (Throwable ex) {
			// We have to catch Throwable, otherwise we will miss
			// NoClassDefFoundError and other subclasses of Error
			throw new ExceptionInInitializerError(ex);
		}
	}
 
	/**
         * Returns the Hibernate configuration that was used to build the
         * SessionFactory.
         * 
         * @return Configuration
         */
	public static Configuration getConfiguration() {
		return configuration;
	}
 
	public static Session getSession() {
		return HibernateUtil.getSessionFactory().getCurrentSession();
	}
 
	/**
         * Returns the global SessionFactory either from a static variable or a JNDI
         * lookup.
         * 
         * @return SessionFactory
         */
	private static SessionFactory getSessionFactory() {
		String sfName = configuration.getProperty(Environment.SESSION_FACTORY_NAME);
		if (sfName != null) {
			try {
				return (SessionFactory) new InitialContext().lookup(sfName);
			} catch (NamingException ex) {
				throw new RuntimeException(ex);
			}
		} else if (sessionFactory == null) {
			rebuildSessionFactory();
		}
		return sessionFactory;
	}
 
	/**
         * Closes the current SessionFactory and releases all resources.
         * <p>
         * The only other method that can be called on HibernateUtil after this one
         * is rebuildSessionFactory(Configuration).
         */
	public static void shutdown() {
		// Close caches and connection pools
		getSessionFactory().close();
 
		// Clear static variables
		sessionFactory = null;
	}
 
	/**
         * Rebuild the SessionFactory with the static Configuration.
         * <p>
         * Note that this method should only be used with static SessionFactory
         * management, not with JNDI or any other external registry. This method
         * also closes the old static variable SessionFactory before, if it is still
         * open.
         */
	public static void rebuildSessionFactory() {
		rebuildSessionFactory(configuration);
	}
 
	/**
         * Rebuild the SessionFactory with the given Hibernate Configuration.
         * <p>
         * HibernateUtil does not configure() the given Configuration object, it
         * directly calls buildSessionFactory(). This method also closes the old
         * static variable SessionFactory before, if it is still open.
         * 
         * @param cfg
         */
	public static void rebuildSessionFactory(Configuration cfg) {
		if (sessionFactory != null && !sessionFactory.isClosed())
			sessionFactory.close();
		if (cfg.getProperty(Environment.SESSION_FACTORY_NAME) != null) {
			cfg.buildSessionFactory();
		} else {
			sessionFactory = cfg.buildSessionFactory();
		}
		configuration = cfg;
	}
Question : A part faire un closeSession() tout moche dans mon formulaire Struts lié à la popup y aurait pas une autre solution ? Ou alors je gère mal le fait d'avoir le fichier Excel écris à la volée, et que la solution de la popup c'est pas génial ?

Ouais je sais j'ai de ces question moi...