Advertisement

01.15.2008 at 07:47AM PST, ID: 23084233
[x]
Attachment Details

hibernate, mysql and jboss and a big big trouble: OutOfMemoryError/Exception. Configuration, code or what else?

Asked by spice_stellina in Enterprise Java Beans (EJB), Jboss Application Server, J2EE Frameworks

Tags: hibernate orm framework

Hi all,
I have this software:
   - MS Windows XP Pro SP2 / MS Windows 2003R2 Enterprise Edition SP1
   - JBoss A.S.-4.0.5.ga ("all" instance)
   - MySql-5.0.24a-community-nt

I'm using "hibernate3.jar" (from Jboss "\server\all\lib" folder), and meta-inf says that is 3.2.0.ga version.
I created a datasource file under "server\all\deploy" in order to have database connection pooling (<jndi-name>jdbc/aup_db</jndi-name>).

In my project I'm using a file named "hibernate.cfg.xml" (I'm enclosing it here).
And I use also this file "PlainJDBCHibernateUtil.java" (enclosing it too).

I have a lot of Stateless Session EJB (please note that I don't use annotations, doclet and so on.. I still use ejb-jar.xml etc etc.. I think I'm using EJB2 and not EJB3. I don't use them for EJB and I don't use them for Hibernate).

I'm desperate because, even if I can use hibernate I have this problem: if there is too much hibernate activity (i.e. CRUD on db==>select, insert, update, delete..) ... JBoss goes into an OutOfMemoryError (I put 512Mb...  :-( ). It seems that used memory is always growing and growing..
I'm blocked here from a lot of time...I spent too much of time! :-( And this thing must be solved urgently.. :-((

Here, an example of how I'm using Hibernate in a Stateless Session EJB method:
----------------
try{
      PlainJDBCHibernateUtil.getCurrentSession().beginTransaction();
      PlainJDBCHibernateUtil.getCurrentSession().clear();
      //do something with DAOs..(save/delete...)
      PlainJDBCHibernateUtil.getCurrentSession().flush();//sometimes it gives error... why? :-(
      //PlainJDBCHibernateUtil.getCurrentSession().clear();//is it needed here?
      PlainJDBCHibernateUtil.getCurrentSession().getTransaction().commit();
} catch (Exception e) {
      if (PlainJDBCHibernateUtil.getCurrentSession().getTransaction() != null) {
            PlainJDBCHibernateUtil.getCurrentSession().getTransaction().rollback();
      }
      throw e;
} finally {
      PlainJDBCHibernateUtil.getCurrentSession().close();
}
----------------

This is all the code (already modified by me) in order to solve this problem... but it seems to me that there is no way... can you help me please?

(Sorry for english.. )

Thanks all,
AnnaStart Free Trial
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:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
FILENAME: "hibernate.cfg.xml"
-------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
 
<hibernate-configuration>
	<session-factory><!-- name="java:hibernate/AupSessionFactory" (vedi sotto) -->
 
 
		<!--
			datasource JNDI name
		-->
		<property name="hibernate.connection.datasource">java:jdbc/aup_db</property>
		
		
		<!--
			The classname of a TransactionFactory to use with Hibernate Transaction API (defaults to JDBCTransactionFactory). 
			eg. classname.of.TransactionFactory
		-->
		<!--property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property--><!-- JTATransactionFactory || ... -->
		
		
		<!--
			A JNDI name used by JTATransactionFactory to obtain the JTA UserTransaction from the application server. 
			eg. jndi/composite/name
		-->
		<!--property name="jta.UserTransaction">java:comp/UserTransaction</property--><!-- java:comp/UserTransaction IS THE DEFAULT ONE -->
		
		
		<!--
			The classname of a TransactionManagerLookup - required when JVM-level caching is enabled or when using hilo generator in a JTA environment. 
			eg. classname.of.TransactionManagerLookup
		-->
		<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property><!-- JBossTransactionManagerLookup || JDBCTransactionFactory || JNDITransactionManagerLookup || ... -->
		
		
		<!--
			The classname of a Hibernate Dialect which allows Hibernate to generate SQL optimized for a particular relational database.
			eg. full.classname.of.Dialect
		-->
		<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property><!-- HSQLDialect MySQLDialect MySQLInnoDBDialect MySQLMyISAMDialect PostgreSQLDialect -->
		
		
		<!--
			Write all SQL statements to console. This is an alternative to setting the log category org.hibernate.SQL to debug. 
			eg. true | false
		-->
		<property name="hibernate.show_sql">false</property><!-- false -->
		
		
		<!--
			Pretty print the SQL in the log and console. 
			eg. true | false
		-->
		<property name="hibernate.format_sql">true</property><!-- false -->
		
		
		<!--
			The SessionFactory will be automatically bound to this name in JNDI after it has been created. 
			eg. jndi/composite/name
		-->
		<property name="hibernate.session_factory_name">java:hibernate/AupSessionFactory</property>
		
		
		<!--
			If enabled, Hibernate will collect statistics useful for performance tuning. 
			eg. true | false
			
			PS:
			If you enable hibernate.generate_statistics, Hibernate will expose a number of metrics that are useful when
			tuning a running system via SessionFactory.getStatistics().
			Hibernate can even be configured to expose these statistics via JMX.
			Read the Javadoc of the interfaces in org.hibernate.stats for more information.
		-->
		<property name="hibernate.generate_statistics">true</property>
		
		
		<!--
			If turned on, Hibernate will generate comments inside the SQL, for easier debugging, defaults to false. 
			eg. true | false
		-->
		<property name="hibernate.use_sql_comments">true</property><!-- Set this to true ONLY for debug purposes --><!-- false -->
		
		
		<!--		
			Specify when Hibernate should release JDBC connections.
			By default, a JDBC connection is held until the session is explicitly closed or disconnected.
			For an application server JTA datasource, you should use after_statement to aggressively release connections after every JDBC call.
			For a non-JTA connection, it often makes sense to release the connection at the end of each transaction, by using after_transaction.
			auto will choose after_statement for the JTA and CMT transaction strategies and after_transaction for the JDBC transaction strategy.
			
			eg. auto (default) | on_close | after_transaction | after_statement
			
			Note that this setting only affects Sessions returned from SessionFactory.openSession.
			For Sessions obtained through SessionFactory.getCurrentSession, the CurrentSessionContext implementation configured for use controls the
			connection release mode for those Sessions. See Section 2.5, “Contextual Sessions”
		-->
		<property name="hibernate.connection.release_mode">auto</property><!-- For an application server JTA datasource, use after_statement -->
		
		
		<!--
			Supply a (custom) strategy for the scoping of the "current" Session.
			See Section 2.5, “Contextual Sessions” for more information about the built-in strategies.
			eg. jta | thread | managed | custom.Class
		-->
		<property name="hibernate.current_session_context_class">thread</property><!-- use jta for connections managed by JBoss || use thread for JDBC: this setting can change your HibernateUtil and application implementation -->
 
 
		<!--
			Enables autocommit for JDBC pooled connections (not recommended). 
			eg. true | false 
		-->
		<property name="hibernate.connection.autocommit">false</property>
		
		
		<!-- #################################### Inizio modifica specifica per MySQL #################################### -->
			<!--
				hibernate.connection.<propertyName>
				Pass the JDBC property propertyName to DriverManager.getConnection().
			-->
			<property name="hibernate.connection.zeroDateTimeBehaviour">convertToNull</property>
		<!-- #################################### Fine modifica specifica per MySQL   #################################### -->
		
		
		<!-- #################################### Inizio modifica specifica per ??? #################################### -->
			<!--
				hibernate.jndi.<propertyName>
				Pass the property propertyName to the JNDI InitialContextFactory.
			-->
			<!--
			<property name="hibernate.jndi.class">org.jnp.interfaces.NamingContextFactory</property>
			-->
		<!-- #################################### Fine modifica specifica per ???   #################################### -->
 
		
		<!--
			mapping files
		-->
		<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/Device.hbm.xml" />
		<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/DeviceCatalog.hbm.xml" />
		<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/DeviceParam.hbm.xml" />
		<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/Email.hbm.xml" />
		<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/Home.hbm.xml" />
		<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/InstantMessenger.hbm.xml" />
		<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/Location.hbm.xml" />
		<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/Logservice.hbm.xml" />
		<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/Mobile.hbm.xml" />
		<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/PlacetypeCatalog.hbm.xml" />
		<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/ServiceCatalog.hbm.xml" />
		<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/User.hbm.xml" />
		<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/User2home.hbm.xml" />
		<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/User2vehicle.hbm.xml" />
		<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/User2work.hbm.xml" />
		<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/UsrServiceProf.hbm.xml" />
		<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/UsrServiceProfParam.hbm.xml" />
		<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/Vehicle.hbm.xml" />
		<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/VirtualPlace.hbm.xml" />
		<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/Work.hbm.xml" />
 
 
	</session-factory>
</hibernate-configuration>
 
-------------------------------------------------------
 
 
 
FILENAME: "PlainJDBCHibernateUtil.java"
-------------------------------------------------------
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class PlainJDBCHibernateUtil {
 
	/** 
	 * Location of "hibernate.cfg.xml" file.
	 * Location should be on the classpath as Hibernate uses #resourceAsStream style lookup for its configuration file. 
	 * The default classpath location of the hibernate config file is in the default package.
	 * Use #setConfigFile() to update the location of the configuration file for the current session.   
	 */
	private static String CONFIG_FILE_LOCATION = "hibernate.cfg.xml";//"hibernate.cfg.xml" || "another_hibernate.cfg.xml"
	private static final ThreadLocal threadLocal = new ThreadLocal();
	private static Configuration configuration = new Configuration();
	private static SessionFactory sessionFactory;
	private static String configFile = CONFIG_FILE_LOCATION;
 
	static {
		try {
 
			sessionFactory = configuration.configure(configFile).buildSessionFactory();
		} catch (Exception e) {
			//Make sure you log the exception, as it might be swallowed
			System.err.println("%%%% Error Creating SessionFactory %%%%");
			throw new ExceptionInInitializerError(e);
		}
	}
 
	/**
	 * 
	 */
	private PlainJDBCHibernateUtil() {
	}
 
	/**
	 * Returns the ThreadLocal Session instance. Lazy initialize the <code>SessionFactory</code> if needed.
	 * @return Session
	 * @throws HibernateException
	 */
	public static Session getCurrentSession() throws HibernateException {//getCurrentSession() instead of getSession()
		Session session = (Session) threadLocal.get();
		if (session == null || !session.isOpen()) {
			if (sessionFactory == null) {
				rebuildSessionFactory();
			}
			//If you use "sessionFactory.openSession()" you MUST handle your Session i.e. session.flush(), session.close(), ...
			//A BETTER WAY of handling your Session is to use "sessionFactory.getCurrentSession()".
			session = (sessionFactory != null) ? sessionFactory.getCurrentSession() : null;
			threadLocal.set(session);
		}
		return session;
	}
 
	/**
	 * Rebuild hibernate session factory
	 */
	public static void rebuildSessionFactory() {
		try {
			sessionFactory = configuration.configure(configFile).buildSessionFactory();
		} catch (Exception e) {
			//Make sure you log the exception, as it might be swallowed
			System.err.println("%%%% Error Creating SessionFactory %%%%");
			throw new ExceptionInInitializerError(e);
		}
	}
 
	/**
	 * Close the single hibernate session instance.
	 * @throws HibernateException
	 */
	public static void closeSession() throws HibernateException {
		Session session = (Session) threadLocal.get();
		threadLocal.set(null);
		if (session != null) {
			session.close();
		}
	}
 
	/**
	 * return session factory
	 * @return SessionFactory
	 */
	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}
 
	/**
	 * set hibernate configuration<br/>
	 * Session factory is set to null and will be rebuilded in the next call
	 */
	public static void setConfigFile(String configFile) {
		PlainJDBCHibernateUtil.configFile = configFile;
		sessionFactory = null;
	}
 
	/**
	 * return hibernate configuration
	 * @return Configuration
	 */
	public static Configuration getConfiguration() {
		return configuration;
	}
 
}
 
-------------------------------------------------------
[+][-]01.16.2008 at 01:18PM PST, ID: 20676255

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.18.2008 at 12:49PM PST, ID: 20694016

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.18.2008 at 01:40PM PST, ID: 20694442

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.19.2008 at 02:27AM PST, ID: 20696775

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.19.2008 at 11:14AM PST, ID: 20698563

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.19.2008 at 02:20PM PST, ID: 20699297

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.21.2008 at 11:18PM PST, ID: 20712448

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]01.24.2008 at 09:09AM PST, ID: 20734894

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.24.2008 at 10:45AM PST, ID: 20735953

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.25.2008 at 03:50AM PST, ID: 20741669

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.25.2008 at 04:02AM PST, ID: 20741721

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.25.2008 at 07:39AM PST, ID: 20743320

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.25.2008 at 08:04AM PST, ID: 20743594

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.25.2008 at 10:10AM PST, ID: 20744778

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]01.25.2008 at 10:46AM PST, ID: 20745108

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.25.2008 at 12:05PM PST, ID: 20745856

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.28.2008 at 01:23AM PST, ID: 20757708

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.28.2008 at 02:06AM PST, ID: 20757881

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Enterprise Java Beans (EJB), Jboss Application Server, J2EE Frameworks
Tags: hibernate orm framework
Sign Up Now!
Solution Provided By: ramazanyich
Participating Experts: 2
Solution Grade: A
 
 
[+][-]01.28.2008 at 02:29AM PST, ID: 20757974

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.28.2008 at 03:26AM PST, ID: 20758191

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628