Question

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

Asked by: spice_stellina

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,
Anna

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;
	}
 
}
 
-------------------------------------------------------

                                  
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:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-01-15 at 07:47:30ID23084233
Tags

hibernate orm framework

Topics

Enterprise Java Beans (EJB)

,

J2EE Frameworks

,

Jboss Application Server

Participating Experts
2
Points
500
Comments
20

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. hibernate and swing
    I have used jsp, mysql db, and hibernate to write a small application before. my question: Is is possible to use hibernate as middleware, in a simple Swing, database application? or hibernate can only be used with webapps.
  2. Advise regarding Hibernate use?
    Hello, My JSP text includes an medium sized web application which uses mysql, and hibernate. I have written an example also using mysql, a datasource and jndi. I am wondering if the use of hibernate to link the java beans used by servlet, jsp pages to mysql can further imp...
  3. JNDI lookup in Spring/Hibernate
    We have a datasource called DBPool defined in a WebLogic server. On the same server, we want to run a stand-alone program to access the same datasource. The stand-alone program uses Spring/Hibernate for the database access. In this stand-alone program, we defined the followin...
  4. tomcat / hibernate / jndi  configuration problem
    Hi folks! I am new to hibernate and have problems with the configuration. tomcat 5.5.17, hibernate 3.2 and I recieve the error org.hibernate.HibernateException: No TransactionManagerLookup specified What could that mean? Please help! regards Albert ERROR MESSAGE ---------...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: ramazanyichPosted on 2008-01-16 at 13:18:18ID: 20676255

in your hibernate.cfg.xml file try to replace:

<property name="hibernate.connection.release_mode">auto</property>

by

<property name="hibernate.connection.release_mode">after_statement</property>

 

by: spice_stellinaPosted on 2008-01-18 at 12:49:12ID: 20694016

mhhhh... I think it's better to tell you what I've done inside jboss. When I installed JBoss (from a zip file).. i put this file "mysql-AUP-ds.xml" (and the "ear" file) in "C:\jboss-4.0.5.GA\server\all\deploy" folder. No other configuration or change in our JBoss A.S. - except for memory (put 512Mb).
I'm telling you these things, because I read (to read) somewhere about people having XA, other people having files  like "xxx-cmp-...xml" and so on... but I don't know those things... :-(
Then...

(whith/having that datasource file), if I put (as you said ;-) )
"<property name="hibernate.connection.release_mode">after_statement</property>"....
ehm.. I think that (in file "PlainJDBCHibernateUtil.java") I  have to call something like "sessionFactory.openSession()" instead of "sessionFactory.getCurrentSession()".. is it correct?

Then.. a doubt... in ejb-jar.xml.... is it setted in the right way? transaction type: bean... or container?
--EJB-JAR.XML-----------
      <session>
         <description><![CDATA[Access to xxxxxxxx]]></description>
         <display-name>AUP Generic</display-name>
         <ejb-name>Generic</ejb-name>
         <home>com.tilab.ca.platform.aup.business.ejb.home.GenericHome</home>
         <remote>com.tilab.ca.platform.aup.business.ejb.facade.GenericRemote</remote>
         <ejb-class>com.tilab.ca.platform.aup.business.ejb.bean.GenericBean</ejb-class>
         <session-type>Stateless</session-type>
         <transaction-type>Bean</transaction-type><!-- Bean x BMT || Container x CMT (Ages ago i put Container here.. instead of Bean.. but I read somewhere that Bean was better.... so I changed this value.........)-->
      </session>
-------------

I have also other two files..containing these rows..
---WEB.XML-----------
      <resource-ref>
            <res-ref-name>jdbc/aup_db</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
            <res-sharing-scope>Shareable</res-sharing-scope>
      </resource-ref>
---------------------

and also this one..
---JBOSS-WEB.XML-----------
      <resource-ref>
            <res-ref-name>jdbc/aup_db</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <jndi-name>jdbc/aup_db</jndi-name>
      </resource-ref>
---------------------

mmmhhh... I'm thinking that my problem can be caused by something here... maybe configuration and/or the code in my stateless session ejb.. is it right?

Thanks for help,
Anna

FILENAME: "mysql-AUP-ds.xml"
---------------------------------------------------
 
<?xml version="1.0" encoding="UTF-8"?>
 
<datasources>
	<local-tx-datasource>
		
		<!-- Database connection pool will be bound into JNDI with the name "java:/jdbc/aup_db" -->
		<!-- <jndi-name>MySqlDS</jndi-name> -->
		<jndi-name>jdbc/aup_db</jndi-name>
		
		<connection-url>jdbc:mysql://163.XXX.XX.XXX:3306/xxx_db</connection-url><!-- PLEASE CHANGE -->
		<driver-class>com.mysql.jdbc.Driver</driver-class><!-- The driver class -->
		<user-name>XXXX</user-name><!-- INSERT YOUR USERNAME -->
		<password>XX</password><!-- INSERT YOUR PASSWORD -->
		
		<min-pool-size>5</min-pool-size><!-- The minimum connections in a pool. Pools are lazily constructed on first use -->
		<max-pool-size>20</max-pool-size><!-- The maximum connections in a pool --><!-- Don't set this any higher than max_connections on your MySQL server, usually this should be a 10 or a few 10's of connections, not hundreds or thousands -->
		<idle-timeout-minutes>5</idle-timeout-minutes><!-- The time before an unused connection is destroyed --><!-- NOTE: This is the check period. It will be destroyed somewhere between 1x and 2x this timeout after last use --><!-- Don't allow connections to hang out idle too long, never longer than what wait_timeout is set to on the server...A few minutes is usually okay here, it depends on your application and how much spikey load it will see -->
		
		<!-- If you're using Connector/J 3.1.8 or newer, you can use our implementation of these to increase the robustness of the connection pool. -->
		<!--example of how to specify class that determines if exception means connection should be destroyed-->
		<!-- org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter -->
		<exception-sorter-class-name>com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter</exception-sorter-class-name>
		
		<!-- Should only be used on drivers after 3.22.1 with "ping" support -->
		<!-- this will be run before a managed connection is removed from the pool for use by a client-->
		<!-- org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker -->
		<valid-connection-checker-class-name>com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker</valid-connection-checker-class-name>
 
		<!-- sql to call when connection is created -->
		<!--new-connection-sql>some arbitrary sql</new-connection-sql--><!-- SELECT CURRENT_TIMESTAMP -->
		
		<!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers-->
		<!--check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql--><!-- SELECT CURRENT_TIMESTAMP -->
 
		<!-- Corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
		<metadata>
			<type-mapping>mySQL</type-mapping>
		</metadata>
		
	</local-tx-datasource>
</datasources>
                                              
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:

Select allOpen in new window

 

by: ramazanyichPosted on 2008-01-18 at 13:40:20ID: 20694442

in your first message you said that if there is some much hibernate activity  you get outofmemory.
Maybe it is a lot of data is retrived from database ?
Could you estimate how much data is read from db ?
also hibernate is using some caching of retrived data. Maybe it is a problem there.
If yo can I suggest also to perform java profiling using some tool (Yourkit from yourkit.com) to see which objects use most of memory.

 

by: spice_stellinaPosted on 2008-01-19 at 02:27:21ID: 20696775

mmmhhh.. the method retrieving more data ...now gets almost 200 records from db. However, I can put a limit, e.g. no more than 1000 records (if needed... maybe last 1000 records).  All I can say is that all the methods are invoked a lot of times (via/through servlets) by users..

Caching: mhh... I think that it's all in the hibernate.cfg.xml.... i putted these rows into that file (now, I'm not using "cache" in my *.hbm.xml files...):

            <!-- ADDED by ANNA 2008 http://www.hibernate.org/hib_docs/reference/en/html_single/#configuration-optional-cacheprovider -->
            <!--
                  This option sets the second level cache provider.
            -->
            <property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property><!-- NoCacheProvider || HashtableCacheProvider || ... -->
            <property name="hibernate.cache.use_second_level_cache">false</property><!-- May be used to completely disable the second level cache, which is enabled by default for classes which specify a <cache> mapping.  -->
            
.... I'm enclosing a code snippet.. of the ejb method wich retrieves a lot of records..
In each method, I create the DAOFactory and needed DAOs..
I'm cheking the "finally" block of each method... in order to discover somewhere if session is not closed properly...

Ok for Yourkit... thanks a lot for suggestion :-) It can be useful ;-)

Thanks, Anna

---EJB SELECT METHOD----------
public Set getUsers() throws Exception {
	Set users = new HashSet(0);
	try {
		logger.setMethodName("getUsers()");
		logger.debug(AUPLog.LOG_MSG_BEGIN);
 
		PlainJDBCHibernateUtil.getCurrentSession().beginTransaction();
		PlainJDBCHibernateUtil.getCurrentSession().clear();
 
		DAOFactory hibernateFactory = DAOFactory.getDAOFactory(DAOFactory.HIBERNATE);//Create the required DAO Factory
		UserDAO userDAO = hibernateFactory.getUserDAO();//Create a DAO
 
		List userDDTOList = userDAO.findAll();
		if (userDDTOList!=null && userDDTOList.size()>0 && userDDTOList.isEmpty()==false){
			com.tilab.ca.platform.aup.dto.domain.User[] userDDTOArray = (com.tilab.ca.platform.aup.dto.domain.User[])userDDTOList.toArray(new com.tilab.ca.platform.aup.dto.domain.User[0]);
			for(int i=0;i<userDDTOArray.length;i++){
				users.add(new User(userDDTOArray[i].getUsername(), userDDTOArray[i].getPassword(), userDDTOArray[i].getFiscalcode(), userDDTOArray[i].getFirstname(), userDDTOArray[i].getLastname(), userDDTOArray[i].getGender(), userDDTOArray[i].getBirthdate(), userDDTOArray[i].getBirthcity(), userDDTOArray[i].getBirthzip(), userDDTOArray[i].getBirthstate(), userDDTOArray[i].getBirthcountry(), userDDTOArray[i].getNationality(), userDDTOArray[i].getCivilstatus()));
			}
		}
 
		PlainJDBCHibernateUtil.getCurrentSession().flush();
		PlainJDBCHibernateUtil.getCurrentSession().getTransaction().commit();
	} catch (Exception e) {
		if (PlainJDBCHibernateUtil.getCurrentSession().getTransaction() != null) {
			PlainJDBCHibernateUtil.getCurrentSession().getTransaction().rollback();
		}
		throw e;
	} finally {
		//PlainJDBCHibernateUtil.getCurrentSession().close();//mmhhh.... no, this is an error!?
		PlainJDBCHibernateUtil.closeSession();//..maybe this is correct.. :S
		logger.debug(AUPLog.LOG_MSG_END);
	}
	return users;
}
 
----DAO FINDALL METHOD---------
	public List findAll() {
		log.debug("finding all User instances");
		try {
			String queryString = "from User";
			Query queryObject = PlainJDBCHibernateUtil.getCurrentSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
 
----EJB UPDATE METHOD---------
public void updateUser(User user) throws UserNotFoundException, java.lang.Exception {
	try {
		logger.setMethodName("updateUser(User user)");
		logger.debug(AUPLog.LOG_MSG_BEGIN);
 
		PlainJDBCHibernateUtil.getCurrentSession().beginTransaction();
		PlainJDBCHibernateUtil.getCurrentSession().clear();
		
		if (user == null || user.getUsername() == null || user.getUsername().length()<=0) {
			throw new ArgumentApplicationException();
		}
		logger.trace("username: " + user.getUsername());
 
		DAOFactory hibernateFactory = DAOFactory.getDAOFactory(DAOFactory.HIBERNATE);//Create the required DAO Factory
		UserDAO userDAO = hibernateFactory.getUserDAO();//Create a DAO
		
		com.tilab.ca.platform.aup.dto.domain.User userDDTO = new com.tilab.ca.platform.aup.dto.domain.User(null, user.getUsername());
		List userDDTOList = userDAO.findByExample(userDDTO);
		if (userDDTOList==null || userDDTOList.size()<=0 || userDDTOList.isEmpty()==true){
			throw new UserNotFoundException();
		}
		userDDTO = ((com.tilab.ca.platform.aup.dto.domain.User[])userDDTOList.toArray(new com.tilab.ca.platform.aup.dto.domain.User[0]))[0];
		
		//updating...
		userDDTO.setBirthcity(user.getBirthcity());
		userDDTO.setBirthcountry(user.getBirthcountry());
		userDDTO.setBirthdate(user.getBirthdate());
		userDDTO.setBirthstate(user.getBirthstate());
		userDDTO.setBirthzip(user.getBirthzip());
		userDDTO.setCivilstatus(user.getCivilstatus());
		userDDTO.setFirstname(user.getFirstname());
		userDDTO.setFiscalcode(user.getFiscalcode());
		userDDTO.setGender(user.getGender());
		//userDDTO.setId(user.getUserid());//no
		userDDTO.setLastname(user.getLastname());
		userDDTO.setNationality(user.getNationality());
		userDDTO.setPassword(user.getPassword());
		//userDDTO.setUsername(user.getUsername());//--username cannot change!!
		
		userDAO.attachDirty(userDDTO);
		
		PlainJDBCHibernateUtil.getCurrentSession().flush();
		PlainJDBCHibernateUtil.getCurrentSession().getTransaction().commit();
	} catch (Exception e) {
		if (PlainJDBCHibernateUtil.getCurrentSession().getTransaction() != null) {
			PlainJDBCHibernateUtil.getCurrentSession().getTransaction().rollback();
		}
		throw e;
	} finally {
		//PlainJDBCHibernateUtil.getCurrentSession().close();//mmhhh.... no, this is an error!?
		PlainJDBCHibernateUtil.closeSession();//..maybe this is correct.. :S
		logger.debug(AUPLog.LOG_MSG_END);
	}
}
 
 
-----DAO ATTACHDIRTY METHOD--------
	public void attachDirty(User instance) {
		log.debug("attaching dirty User instance");
		try {
			PlainJDBCHibernateUtil.getCurrentSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
                                              
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:

Select allOpen in new window

 

by: ramazanyichPosted on 2008-01-19 at 11:14:01ID: 20698563

It seems indeed problem is in the getUsers() method call.
Where do you use returned users list? do you clean this list after finishing of usage?
I will suggest do not get all users at one request. If you need to update whole users then get only block of them.Do modifications and then get next block until you finish whole users managing.

 

by: spice_stellinaPosted on 2008-01-19 at 14:20:40ID: 20699297

Is problem in getUsers()?  :-o

PS: When I'm working with hibernate(and mysql db), I use this class "com.tilab.ca.platform.aup.dto.domain.User" as Domain Data Transfer Object (DDTO). When not specified, I'm using another class named "User" but this one is a Custom(or Client??) Data Transfer Object (CDTO), it's located in another package... and I use it in order to return result(s) to my servlet :-)

"Where do you use returned users list? do you clean this list after finishing of usage?"
are you talking about "userDDTOList"? Ehm.. when finishing use, I call methods "flush" and "commit"... ehm I don't use that list.. no more. Have I to set it to null before exiting from ejb method or use "clear" method? Any ideas?

Usually I get multiple records when doing a select on db (as in getUsers()). When I have to update something, I'm doing update on a single User, a single record..(as in updateUser(User user)).. I don't do update on multiple records at once.. sorry!

Thanks for help,
Anna

 

by: vinscomPosted on 2008-01-21 at 23:18:24ID: 20712448

Try adding parameter to your JBoss run.bat file

Take for example in my case it was
-Xms512m -Xmx1024m -XX:MaxPermSize=256m

Problem could occure sometime because of Java Heap not growing according to requirement, out of memory error comes. It happens with Sun Java 1.5, it might not happen with other JVM like JRockit

 

by: spice_stellinaPosted on 2008-01-24 at 09:09:40ID: 20734894

Hi vinscom,
thanks for settings ;-)

I tried them as you suggested and then also with little changes.

I'm trying to "stress" my application and jboss with a lot of multiple request....  in order to see if jboss, hibernate and my application can serve request with no problems/no errors/no memory and cpu issues... but the result is the same :-(

Sometimes JBoss says "java.lang.OutOfMemoryError: java heap space" ... and sometimes does not.
When it says nothing at all, I saw/can see (to see) in task manager that "cpu usage" was/is 100%.. and I can tell you that it's a "never ending 100% cpu usage"... until I kill the process manually :-(

I'm running only jboss and no other tool or applications or services.

I tried "YourKit" in order to try to detect what's wrong/what's the matter... but with no success (I think that is my problem... troubles in english language comprhension and translating..).
Then, I found and installed  "JProfiler v.5.1.2 - please see  www.jprofiler.com ".. and It seems that this tool has been installed properly/succesfully...  I'm trying to understand how this tool works and why memory is not de-allocated/re-ri-allocated and why there is "100% cpu usage"...

ps: yes, you're right: I have a Sun JDK, v.1_5_09

Help would greatly be appreciated, thanks
Anna

 

by: spice_stellinaPosted on 2008-01-24 at 10:45:58ID: 20735953

ps2: I installed JProbe v.7.0.2 too ( see  http://www.quest.com/jprobe  )

 

by: spice_stellinaPosted on 2008-01-25 at 03:50:28ID: 20741669

Hi all,
it seems that "com.tilab.ca.platform.aup.dto.domain.User" classes (DDTO - used by Hibernate) are allocated and then de-allocated/destroyed (in JProfiler, I clicked on "Run garbace collector" button too.. after invoking my method "getUsers()").

It seems that my problem is this class: "com.tilab.ca.platform.aup.datatype.User" (I use this class as CDTO in order to return data to my servlet). All instances of that class, are created/allocated and then NOT de-allocated/destroyed. So, I have the previous x instances plus the n new instances when I'm invoking that method.

e.g. 1st round:
0 previous instances, then invoking method (wich implies 127 instances), then have something like 0+127=127

e.g. 2nd round:
127 previous instances, invoking the same method, then have something like 127+127=254... and so on.

If I'm not wrong and I have understood (to understand/comprhension) the situation,  I'm supposing that problem is located in my servlet.. but I'm unable to understand why there is this problem..and where/how is generated..

I'm enclosing code... please let me know if you have got any ideas... thank you all.
Anna

==FILE: HttpServletImpl ===============================================
 
package com.tilab.ca.platform.aup.newutil;
 
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
 
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
 
public abstract class HttpServletImpl extends HttpServlet implements HttpServletStatusCode {
	
	protected static final String METHOD_GET = "GET";
	protected static final String PARAMETER_NAME_PREFIX = "p_";
	
	
	/**
	 * 
	 * @param servletMethodName
	 * @return
	 */
	protected abstract String[] createRealParameterNames(String servletMethodName);
	
	
	//http://hostname.com:80/mywebapp/servlet/MyServlet/a/b;c=123?d=789
	
	/**
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	protected HttpServletRequest fixCustomSintax(HttpServletRequest request, HttpServletResponse response) {
		if (METHOD_GET.equalsIgnoreCase(request.getMethod())) {//DELETE HEAD GET OPTIONS POST PUT TRACE
			//--> http://hostname.com:80/mywebapp/servlet/MyServlet/a/b;c=123
			String pathInfo = request.getPathInfo();// /a/b;c=123 --> GET with "/" sintax//ATTENTION!!! It seems that could NOT manage-handle "p1//p3" sintax (with double slash).
			if (pathInfo!=null && pathInfo.length()>0){
				// GET with "/" sintax
				pathInfo = pathInfo.substring(1, pathInfo.length());//trying to cut/remove the 1st charachter i.e. "/".
				String[] splittedPathInfo = pathInfo.split("/");
				String[] realParameterNames = createRealParameterNames(HttpServletUtil.getServletMethodName(request));
				for(int i=0;i<splittedPathInfo.length;i++){
					String[] requestValueParamStringArray = new String[1];
					requestValueParamStringArray[0]=splittedPathInfo[i];
					if (realParameterNames!=null && realParameterNames.length>0 && i<realParameterNames.length){
						//ATTENTION!!! with "request.setAttribute" we're modifying "request" object...
						request.setAttribute(realParameterNames[i], requestValueParamStringArray);//Please use this sintax: request.setAttribute(String key, String[] value);
					} else {
						//ATTENTION!!! with "request.setAttribute" we're modifying "request" object...
						request.setAttribute((PARAMETER_NAME_PREFIX+i), requestValueParamStringArray);//Please use this sintax: request.setAttribute(String key, String[] value);
					}
					requestValueParamStringArray = null;
				}
			}
		}
 
		return request;
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	protected HashMap getParametersAndAttributes(HttpServletRequest request, HttpServletResponse response){
		HashMap hashMap = new HashMap(0);
 
		request = fixCustomSintax(request, response);//GET with custom sintax...
		
		Enumeration paramNames = request.getParameterNames();//All parameters from html form (<input>...</input>, standard GET/POST)
		while(paramNames.hasMoreElements()) {
			String paramName = (String)paramNames.nextElement();
			String[] paramValues = request.getParameterValues(paramName);
			hashMap.put(paramName, paramValues);//Please use this sintax: request.setAttribute(String key, String[] value);
		}
 
		Enumeration attributeEnumeration = request.getAttributeNames();//(set programatically)
		for (; attributeEnumeration.hasMoreElements(); ) {
			String attributeName = (String)attributeEnumeration.nextElement();
			hashMap.put(attributeName, request.getAttribute(attributeName));//Please use this sintax: request.setAttribute(String key, Object value);//Attention! "value" can be a String or a String[] or a YourCustomObject...
		}
 
		return hashMap;
	}
	
 
	protected final void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGetOrPostWrapper(request, response);
	}
 
 
	protected final void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGetOrPostWrapper(request, response);
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	private void doGetOrPostWrapper(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGetOrPost(request, response, request.getSession());
	}
 
	/**
	 * This method handles both GET and POST requests.
	 * This method is called by the servlet container to process a GET or POST request.
	 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 * @param request HttpServletRequest
	 * @param response HttpServletResponse
	 * @param currentSession HttpSession
	 */
	protected abstract void doGetOrPost(HttpServletRequest request, HttpServletResponse response, HttpSession currentSession) throws ServletException, IOException;
 
 
}
 
 
 
 
==FILE: UserProfileRestServlet==========================================
 
package com.tilab.ca.platform.aup.web;
 
import java.io.IOException;
import java.net.URLDecoder;
import java.rmi.RemoteException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Vector;
 
import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
import com.tilab.ca.platform.aup.datatype.User;
import com.tilab.ca.platform.aup.datatype.aggregator.NullOrEmptyHashSet;
import com.tilab.ca.platform.aup.datatype.integrator.CtxResp;
import com.tilab.ca.platform.aup.datatype.remapper.ParamSimpleMap;
import com.tilab.ca.platform.aup.datatype.remapper.ServiceParamSimpleMap;
import com.tilab.ca.platform.aup.business.ejb.facade.UserProfileRemote;
import com.tilab.ca.platform.aup.business.ejb.home.UserProfileHome;
import com.tilab.ca.platform.aup.exceptions.UserAlreadyExistException;
import com.tilab.ca.platform.aup.exceptions.UserNotFoundException;
import com.tilab.ca.platform.aup.exceptions.common.ArgumentApplicationException;
import com.tilab.ca.platform.aup.newutil.HttpServletImpl;
import com.tilab.ca.platform.aup.newutil.HttpServletUtil;
import com.tilab.ca.platform.aup.util.DateTimeUtil;
import com.tilab.ca.platform.aup.utils.AUPLog;
import com.tilab.ca.platform.aup.utils.AupUtilities;
import com.tilab.ca.platform.aup.utils.Corrector;
import com.tilab.ca.platform.aup.utils.ServletPrintUtilities;
 
 
public class UserProfileRestServlet extends HttpServletImpl {
	
	private static final long serialVersionUID = 1L;
	private UserProfileHome home;
	private AUPLog logger = AUPLog.getInstance();
 
	
	public UserProfileRestServlet() {
		super();
		logger.setMethodName("UserProfileRestServlet()");
		logger.debug(AUPLog.LOG_MSG_BEGIN);
		logger.debug(AUPLog.LOG_MSG_END);
	}
 
 
 
	public void init(ServletConfig config) throws ServletException {
		logger.setMethodName("init");
		logger.debug(AUPLog.LOG_MSG_BEGIN);
		//super.init(config);//FIXME remove me..(?)
		try {
			Context context = new InitialContext();
			Object ref = context.lookup("java:/comp/env/ejb/UserProfile");
			home = (UserProfileHome) PortableRemoteObject.narrow(ref, UserProfileHome.class);
		} catch (Exception e) {
			throw new ServletException("Lookup of java:/comp/env/ failed");
		} finally{
			logger.debug(AUPLog.LOG_MSG_END);
		}
	}
 
	/**
	 * 
	 * @param servletMethodName
	 * @return
	 */
	protected String[] createRealParameterNames(String servletMethodName) {
		//Adjust parameter names (useful when has been used GET with "/" sintax).
		String[] realParameterNames = null;
		if (servletMethodName!=null && servletMethodName.length()>0){//servletMethodName: it's my "action" parameter (see MVC)
			if ("main".equals(servletMethodName)){//TODO jsp/jstl
				realParameterNames = new String[1];
				realParameterNames[0] = "action";
			} else if ("getUsers".equals(servletMethodName)){
				//realParameterNames = new String[0];
			} else if ("getUserByUserName".equals(servletMethodName)){
				realParameterNames = new String[1];
				realParameterNames[0] = "username";
			} else {
				//no parameters required or unavailable/unknown method.
			}
		}
		return realParameterNames;
	}
 
	/**
	 * This method handles both GET and POST requests.
	 * This method is called by the servlet container to process a GET or POST request.
	 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 * @param request HttpServletRequest
	 * @param response HttpServletResponse
	 * @param currentSession HttpSession
	 */
	protected void doGetOrPost(HttpServletRequest request, HttpServletResponse response, HttpSession currentSession) throws ServletException, IOException {
		Object result = null;
		try{
			UserProfileRemote bean = home.create();
			HashMap hashMap = getParametersAndAttributes(request, response);
			String[] realParameters = createRealParameterNames(HttpServletUtil.getServletMethodName(request));
 
			if ("getUsers".equals(HttpServletUtil.getServletMethodName(request))){
				try{
					result = bean.getUsers();
				} catch(ArgumentApplicationException e){
					result = new CtxResp("unknown", "unknown", "userProfile", HttpServletUtil.getServletMethodName(request), "ERROR", SC_400_BAD_REQUEST, "Bad request. "+e.getClass().getSimpleName());
				} catch (UserNotFoundException unfe) {
					result = new CtxResp("unknown", "unknown", "userProfile", HttpServletUtil.getServletMethodName(request), "ERROR", SC_404_NOT_FOUND, "Not Found. " + unfe.getClass().getSimpleName());
				} catch (MobileNotFoundException mnfe) {
					result = new CtxResp("unknown", "unknown", "userProfile", HttpServletUtil.getServletMethodName(request), "ERROR", SC_404_NOT_FOUND, "Not Found. " + mnfe.getClass().getSimpleName());
				} catch(RuntimeException e){
					result = new CtxResp("unknown", "unknown", "userProfile", HttpServletUtil.getServletMethodName(request), "ERROR", SC_500_INTERNAL_SERVER_ERROR, "Internal server error. "+e.getClass().getSimpleName());
				} catch(Throwable e){
					result = new CtxResp("unknown", "unknown", "userProfile", HttpServletUtil.getServletMethodName(request), "ERROR", SC_500_INTERNAL_SERVER_ERROR, "Internal server error. "+e.getClass().getSimpleName());
				}
			} else if ("getUserByUserName".equals(HttpServletUtil.getServletMethodName(request))){
				String username = null;
 
				for(int i=0; i<realParameters.length;i++){//TODO emproove your code... replicated code :-(
					String[] tmp = (String[])hashMap.get(realParameters[i]);//0=username, ...//we are naming our parameters in only one way/mode-modality and with only one name.
					if (tmp!=null && tmp.length>0){
						switch (i) {
						case 0:
							username = tmp[0];
							break;
						default:
							break;
						}
					}
					tmp=null;
				}
 
				//ctxml....
				try{
					result = bean.getUserByUserName(username);
				} catch(ArgumentApplicationException e){
					result = new CtxResp("unknown", "unknown", "userProfile", HttpServletUtil.getServletMethodName(request), "ERROR", SC_400_BAD_REQUEST, "Bad request. "+e.getClass().getSimpleName());
				} catch (UserNotFoundException unfe) {
					result = new CtxResp("unknown", "unknown", "userProfile", HttpServletUtil.getServletMethodName(request), "ERROR", SC_404_NOT_FOUND, "Not Found. " + unfe.getClass().getSimpleName());
				} catch (MobileNotFoundException mnfe) {
					result = new CtxResp("unknown", "unknown", "userProfile", HttpServletUtil.getServletMethodName(request), "ERROR", SC_404_NOT_FOUND, "Not Found. " + mnfe.getClass().getSimpleName());
				} catch(RuntimeException e){
					result = new CtxResp("unknown", "unknown", "userProfile", HttpServletUtil.getServletMethodName(request), "ERROR", SC_500_INTERNAL_SERVER_ERROR, "Internal server error. "+e.getClass().getSimpleName());
				} catch(Throwable e){
					result = new CtxResp("unknown", "unknown", "userProfile", HttpServletUtil.getServletMethodName(request), "ERROR", SC_500_INTERNAL_SERVER_ERROR, "Internal server error. "+e.getClass().getSimpleName());
				}
			} else {
				//??????????
				result = new CtxResp("unknown", "unknown", "userProfile", HttpServletUtil.getServletMethodName(request), "ERROR", SC_404_NOT_FOUND, null);
			}
		} catch(Throwable e){
			result = new CtxResp("unknown", "unknown", "userProfile", HttpServletUtil.getServletMethodName(request), "ERROR", SC_500_INTERNAL_SERVER_ERROR, "Internal server error. "+e.getClass().getSimpleName());
			e.printStackTrace();
		} finally{
			//PRINTING...
			try{
				ServletPrintUtilities.printContextML(result, response);//ctxml..
			} catch(Throwable e){
				e.printStackTrace();//troubles while printing...
			}
		}
	}
	
 
}
                                              
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:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:

Select allOpen in new window

 

by: ramazanyichPosted on 2008-01-25 at 04:02:43ID: 20741721

try to free your result object after printing:

so you code:
try{
                        ServletPrintUtilities.printContextML(result, response);//ctxml..
                  } catch(Throwable e){
                        e.printStackTrace();//troubles while printing...
                  }


replace it by
try{
                        ServletPrintUtilities.printContextML(result, response);//ctxml..
                  } catch(Throwable e){
                        e.printStackTrace();//troubles while printing...
                  }finally{
                            result=null;
                         }

 

by: spice_stellinaPosted on 2008-01-25 at 07:39:24ID: 20743320

Hi ramazanyich,
I put the finally block and that line of code... and then tried again... with no success... sorry! :-(

Then, I tried to do another change: please see  enclosed code snippet... with that change it's all OK, it de-allocates/destroys all that objects-instances (but of course I can't print out results..). So I'm supposing that problem now it's inside there...  in printing classes...
(those classes use betwixt library too... I suppose that it's not a betwixt problem.. it' a code problem..)..

=== finally block: modified in this way..: ======================
 
} finally{
	//PRINTING...
	/*
	try{
		//ServletPrintUtilities.printContextML(result, response);
		ServletPrintUtilities servletPrintUtilities = new ServletPrintUtilities();
		servletPrintUtilities.printContextML(result, response);
	} catch(Throwable e){
		e.printStackTrace();
		//troubles while printing...
	} finally {
		//result = null;
	}
	*/
}

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:

Select allOpen in new window

 

by: spice_stellinaPosted on 2008-01-25 at 08:04:44ID: 20743594

I'm enclosing printing class...

any ideas?

Thanks,
Anna

== FILE: ServletPrintUtilities ========================================
 
package com.tilab.ca.platform.aup.utils;
 
import java.beans.IntrospectionException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
 
import javax.servlet.http.HttpServletResponse;
 
import org.apache.commons.betwixt.BindingConfiguration;
import org.apache.commons.betwixt.XMLIntrospector;
import org.apache.commons.betwixt.io.BeanWriter;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
 
import com.tilab.ca.platform.aup.datatype.UserProfile;
 
 
public class ServletPrintUtilities {
 
	private BindingConfiguration bindingConfiguration = null;
	private XMLIntrospector xmlIntrospector = null;
	
	private final String contextMLXsd = "ContextML-1.1.xsd";//please choose from one of these options: "ContextML-1.0.xsd" or "ContextML-1.1.xsd"
	private final String xmlDeclaration = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";//ISO-8859-1//UTF-8
	
	private AUPLog logger = AUPLog.getInstance();
 
	/**
	 * Default constructor
	 */
	public ServletPrintUtilities(){
		BeanWriter beanWriter = new BeanWriter();
		beanWriter.getBindingConfiguration().setMapIDs(false);
 
		DateObjectStringConverter dosc = new DateObjectStringConverter();
		beanWriter.getBindingConfiguration().setObjectStringConverter(dosc);
 
		beanWriter.enablePrettyPrint();
		beanWriter.setWriteEmptyElements(false);
		InputStream is = null;
 
		if (contextMLXsd.equalsIgnoreCase("ContextML-1.0.xsd")) {
			is = UserProfile.class.getResourceAsStream("/betwixt-config/beanToXmlMapping-1.0.betwixt");//beanToXmlMapping.betwixt
		} else {
			is = UserProfile.class.getResourceAsStream("/betwixt-config/beanToXmlMapping-1.1.betwixt");
		}
 
		try {
			beanWriter.getXMLIntrospector().register(new InputSource(is));
		} catch (IntrospectionException e) {
			logger.error("", e);
		} catch (IOException e) {
			logger.error("", e);
		} catch (SAXException e) {
			logger.error("", e);
		}
		bindingConfiguration = beanWriter.getBindingConfiguration();
		xmlIntrospector = beanWriter.getXMLIntrospector();
	}
 
 
	public void printXMLfile(HttpServletResponse response, String s) throws IOException {
		response.setContentType("text/xml");
		PrintWriter out = response.getWriter();
		out.print(s);
		out.flush();
		out.close();
	}
 
 
	/**
	 * This method helps you in showing/printing contextML messages.
	 * @param object Object
	 * @param response HttpServletResponse
	 * @throws IOException
	 */
	public void printContextML(Object object, HttpServletResponse response) throws IOException {
		logger.setMethodName("printContextML(Object object, HttpServletResponse response)");
		logger.debug(AUPLog.LOG_MSG_BEGIN);
		response.setContentType("text/xml");
		PrintWriter out = response.getWriter();//ATTENTION
		BeanWriter beanWriter = new BeanWriter(out);//ATTENTION (we're trying to write contextML -via betwixt- into the response object..(see line above too))
		beanWriter.setBindingConfiguration(bindingConfiguration);
		beanWriter.setXMLIntrospector(xmlIntrospector);
		beanWriter.writeXmlDeclaration(xmlDeclaration);
		try {
			//beanWriter.write(Corrector.correct(object));
			Corrector corrector = new Corrector();
			beanWriter.write(corrector.correct(object));
		} catch (IOException e) {
			logger.error("", e);
		} catch (SAXException e) {
			logger.error("", e);
		} catch (IntrospectionException e) {
			logger.error("", e);
		}
		out.flush();
		out.close();
		
		object = null;
		logger.debug(AUPLog.LOG_MSG_END);
	}
	
	/**
	 * This method can take, as input parameter, your CDTO(s) and "translate" it/them into contextML.
	 * e.g.: com.tilab.ca.platform.aup.datatype.User (single/only one datatype)
	 * e.g.: Set/HashSet of multiple CDTOs (like com.tilab.ca.platform.aup.datatype.User, com.tilab.ca.platform.aup.datatype.Work, ...)
	 * @param datatype Object
	 * @return String
	 * @throws Exception
	 */
	public String toContextML(Object datatype) throws IOException, Exception {
		logger.setMethodName("toContextML(Object datatype)");
		logger.debug(AUPLog.LOG_MSG_BEGIN);
		String contextML=null;
 
		StringWriter outputWriter = new StringWriter(); 
 
		BeanWriter beanWriter = new BeanWriter(outputWriter);
		beanWriter.setBindingConfiguration(bindingConfiguration);
		beanWriter.setXMLIntrospector(xmlIntrospector);
		beanWriter.writeXmlDeclaration(xmlDeclaration);
 
		try {
			//beanWriter.write(Corrector.correct(datatype));
			Corrector corrector = new Corrector();
			beanWriter.write(corrector.correct(datatype));
		} catch (IOException e) {
			logger.error("", e);
		} catch (SAXException e) {
			logger.error("", e);
		} catch (IntrospectionException e) {
			logger.error("", e);
		}
 
		contextML = "";
		contextML += outputWriter.toString();
		if (contextML!=null) {
			logger.trace("contextML:"+contextML);
		} else {
			logger.trace("contextML: NULL!!");
		}
 
		outputWriter.flush();
		outputWriter.close();
		
		logger.debug(AUPLog.LOG_MSG_END);
		return contextML;
	}
 
}
                                              
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:

Select allOpen in new window

 

by: ramazanyichPosted on 2008-01-25 at 10:10:28ID: 20744778

try to do
 beanWriter.flush();

beanWriter.close();

in your finally block

 

by: spice_stellinaPosted on 2008-01-25 at 10:46:15ID: 20745108

Yes, you're right I found the same problem...

            beanWriter.flush();//YOU'VE FORGOTTEN THIS LINE!! :-P
            beanWriter.close();//YOU'VE FORGOTTEN THIS LINE!! :-P
            
            beanWriter = null;
            out = null;

...tried again to test... but there is still the same problem... :-(
Cannot de-allocate/destroy instances/objects... no comment..

 

by: ramazanyichPosted on 2008-01-25 at 12:05:09ID: 20745856

and what is the class Corrector ?? What it is doing with objects ?

 

by: spice_stellinaPosted on 2008-01-28 at 01:23:19ID: 20757708

I'm enclosing Corrector class ...

This class analyse the objects, and if neeeded it corrects them. In order to print xml in another way (not in the standard way but in another way)...

So, xml output can be different... different tags/elements and so on...

Anna

package com.tilab.ca.platform.aup.utils;
 
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
 
import com.tilab.ca.platform.aup.datatype.aggregator.LotOfCtxEl;
import com.tilab.ca.platform.aup.datatype.aggregator.NullOrEmptyHashSet;
import com.tilab.ca.platform.aup.datatype.aggregator.UniqueCtxEl;
import com.tilab.ca.platform.aup.datatype.integrator.DatatypeExt;
 
 
public class Corrector {
	
	private AUPLog logger = AUPLog.getInstance();
	
	/**
	 * Default constructor
	 */
	public Corrector(){
		//...
	}
	
 
	/**
	 * Is same datatype?
	 * @param obj1 Object
	 * @param obj2 Object
	 * @return boolean
	 */
	private boolean isSameDT(Object obj1, Object obj2) {
		logger.setMethodName("isSameDT(Object obj1, Object obj2)");
		logger.debug(AUPLog.LOG_MSG_BEGIN);
		boolean isSameDT = false;
		if ((obj1.getClass()).getName().equalsIgnoreCase((obj2.getClass()).getName())) {
			isSameDT = true;
		}
		logger.debug(AUPLog.LOG_MSG_END);
		return isSameDT;
	}
 
	/**
	 * It checks if they are of the same type and if they can be "to put together two objects" and then obtain only one object (CtxEl).
	 * @param obj1 Object
	 * @param obj2 Object
	 * @return boolean
	 */
	private boolean isUniqueCtxEl(Object obj1, Object obj2) {
		logger.setMethodName("isUniqueCtxEl(Object obj1, Object obj2)");
		logger.debug(AUPLog.LOG_MSG_BEGIN);
		boolean isUniqueCtxEl = false;
		if (isSameDT(obj1, obj2)==true) {
			if (
					((DatatypeExt)obj1)!=null && ((DatatypeExt)obj2)!=null &&
 
					((DatatypeExt)obj1).getEntityType()!=null && ((DatatypeExt)obj2).getEntityType()!=null &&
					((DatatypeExt)obj1).getEntityType().equals(((DatatypeExt)obj2).getEntityType()) &&
 
					((DatatypeExt)obj1).getEntityId()!=null && ((DatatypeExt)obj2).getEntityId()!=null &&
					((DatatypeExt)obj1).getEntityId().equals(((DatatypeExt)obj2).getEntityId()) &&
 
					((DatatypeExt)obj1).getScope()!=null && ((DatatypeExt)obj2).getScope()!=null &&
					((DatatypeExt)obj1).getScope().equals(((DatatypeExt)obj2).getScope()) &&
 
					((DatatypeExt)obj1).getParA_n()!=null && ((DatatypeExt)obj2).getParA_n()!=null &&
					((DatatypeExt)obj1).getParA_n().equals(((DatatypeExt)obj2).getParA_n())
			) {
				isUniqueCtxEl = true;
			}
		}
		logger.debug(AUPLog.LOG_MSG_END);
		return isUniqueCtxEl;
	}
 
	/**
	 * We pass a DT (datatype) as input parameter and method returns the same object with eventual corrections...
	 * If I pass erroneously a Set (HashSet), it returns always a null object.
	 * @param objToCheck Object
	 * @return Object
	 */
	private Object correctDT(Object objToCheck) {
		logger.setMethodName("correctDT(Object objToCheck)");
		logger.debug(AUPLog.LOG_MSG_BEGIN);
		//entityId: I have to put a value (it's a String object).
		//object: supposing that this is a simple object and not an HashSet.
		//based on the object, I invoke a method or another one: in certain cases (it depends from method), I have to pass no parameters or n parameters. 
		//The invoked method will give me a String object or an Integer or an int... something like that.
 
		Object object = objToCheck;
		if (!(object instanceof Set)) {
			if (object instanceof DatatypeExt) {
				Class objectClass = object.getClass();
				logger.trace("objectClass.getName(): " + objectClass.getName());
				String entityType = null;
				String entityId = null;
				entityType = ((DatatypeExt)object).getEntityType();//userName
				if (entityType!= null && !entityType.equalsIgnoreCase("") && !entityType.equalsIgnoreCase("unknown")) {
					try {
						Method[] publicMethods = objectClass.getMethods();
						if (publicMethods!= null && publicMethods.length>0) {
							for(int i=0; i<publicMethods.length;i++) {
								logger.trace("i:"+i+":   ===>" + publicMethods[i].getName()+"<===");
								if ((publicMethods[i].getName()).equalsIgnoreCase("get"+entityType)) {
									logger.trace("This method requires parameter(s) or not?");
									Class[] parameterTypes = publicMethods[i].getParameterTypes();
									if (parameterTypes.length==0) {
										logger.trace("No parameter(s) required");
										Object result = publicMethods[i].invoke(object, new Object[0]);//objectClass
										if (result instanceof String) {
											entityId = (String)result;
										} else if (result instanceof Integer ) {
											if (((Integer)result)!= null ) {
												entityId = ""+((Integer)result).intValue();
											} else {
												entityId = null;
											}
										} else {
											entityId = ""+result;
										}
										((DatatypeExt)object).setEntityId(entityId);
										logger.trace("entityId vale:---*"+entityId+"*---");
									} else {
										//It was supposed you were (to be) not here...
									}
									break;
								}
								if (i==publicMethods.length-1) {
									//Last round: method does not exist or method is not public, entityType has a wrong value.
								}
							}
						} else {
							logger.trace("publicMethods is null!!!!!");
						}
						/*
			        } catch (NoSuchMethodException e) {
			            logger.error("", e);
						 */
					} catch (IllegalAccessException e) {
						logger.error("", e);
					} catch (InvocationTargetException e) {
						logger.error("", e);
					} catch (Exception e) {
						logger.error("", e);
					}
				} else {
					logger.trace("entityType is null or unknown!!!!!");
				}
			} else {
				logger.trace("object does NOT extend DatatypeExt!!!!!");
			}
 
			object = (object.getClass()).cast(object);
 
		} else {
			object = null;
			logger.trace("object is an HashSet!!!!!");
		}
		logger.debug(AUPLog.LOG_MSG_END);
		return object;
	}
 
	/**
	 * It checks object and do something (or nothing) with it..
	 * @param object
	 * @return Object
	 */
	public Object correct(Object objToCheck) {
		logger.setMethodName("correct(Object objToCheck)");
		logger.debug(AUPLog.LOG_MSG_BEGIN);
		Object object = objToCheck;
		
		if (object instanceof NullOrEmptyHashSet && object !=null) {
			((NullOrEmptyHashSet)object).setObject(correctDT(((NullOrEmptyHashSet)object).getObject().getClass().cast(((NullOrEmptyHashSet)object).getObject())));
 
			
			if (object!=null && ((NullOrEmptyHashSet)object).getObject() instanceof DatatypeExt && ((NullOrEmptyHashSet)object).getObject()!=null) {
				((NullOrEmptyHashSet)object).setEntityType(((DatatypeExt)((NullOrEmptyHashSet)object).getObject()).getEntityType());
				((NullOrEmptyHashSet)object).setEntityId(((DatatypeExt)((NullOrEmptyHashSet)object).getObject()).getEntityId());
				((NullOrEmptyHashSet)object).setScope(((DatatypeExt)((NullOrEmptyHashSet)object).getObject()).getScope());
				((NullOrEmptyHashSet)object).setParA_n(((DatatypeExt)((NullOrEmptyHashSet)object).getObject()).getParA_n());
				((NullOrEmptyHashSet)object).setParS_n(((DatatypeExt)((NullOrEmptyHashSet)object).getObject()).getParS_n());
				((NullOrEmptyHashSet)object).setPar_n(((DatatypeExt)((NullOrEmptyHashSet)object).getObject()).getPar_n());
				((NullOrEmptyHashSet)object).setObject(null);
			} else {
				logger.trace("Troubles, not extending from DatatypeExt");
			}
			
		} else if (!(object instanceof Set)) {
			if (
					(object instanceof com.tilab.ca.platform.aup.datatype.integrator.CtxResp) ||
					(object instanceof com.tilab.ca.platform.aup.datatype.UserProfile) ||
					(object instanceof com.tilab.ca.platform.aup.datatype.ServiceProfile) ||
					(object instanceof com.tilab.ca.platform.aup.datatype.DeviceParam) ||
					(object instanceof com.tilab.ca.platform.aup.datatype.remapper.ServiceParamSimpleMap) ||
					(object instanceof com.tilab.ca.platform.aup.datatype.remapper.ParamSimpleMap)
			) {
				/* We have to return that object, as it is..
				 * CtxResp
				 * UserProfile
				 * ServiceProfile
				 * DeviceParam
				 * ServiceParamSimpleMap
				 */
				object = correctDT(object);
				object = (object.getClass()).cast(object);
			} else {
				//logger.trace("it isn't a Set, it's a simple DT. We have to return UniqueCtxEl.");
				object = correctDT(object);
				object = new UniqueCtxEl(object);
			}
		} else {
			//object is an HashSet...
			if (((Set)object)!=null && !((Set)object).isEmpty() && ((Set)object).size()>0){
				Object[] objects = (Object[])((Set)object).toArray(new Object[0]);//all DTs...
				//Checking if HashSet is homogeneus..
				boolean isSameDT = false;
				boolean isUniqueCtxEl = false;
				for(int i=0;i<objects.length;i++) {
					objects[i] = correctDT(objects[i]);
					if (i==0) {
						isSameDT = true;
						isUniqueCtxEl = true;
					} else {
						if (isSameDT(objects[i], objects[i-1]) == false) {
							isSameDT=false;
							break;
						} else {
							if (isUniqueCtxEl(objects[i], objects[i-1]) == false) {
								isUniqueCtxEl = false;
								break;
							}
						}
					}
				}
				object = new HashSet(0);
				for(int i=0;i<objects.length;i++) {
					((HashSet)object).add(objects[i]);//((objects[i]).getClass()).cast(objects[i])
				}
				if(isSameDT && isUniqueCtxEl) {
					if (objects.length==1 && (objects[0] instanceof com.tilab.ca.platform.aup.datatype.BdaddressUser)) {
						object = new LotOfCtxEl((HashSet)object);
					} else {
						//==> it's ok for a unique CtxEl, with one or more parS (same type, with simple DT(s)... and not compound.).
						logger.trace("It's a Set, same DT and isuniqueCtxEl =true. Using UniqueCtxEl.");
						object = new UniqueCtxEl((HashSet)object);
					}
				} else {
					object = new LotOfCtxEl((HashSet)object);
					logger.trace("This is a Set with some values but with different entities/entity.....using LotOfCtxEl");
				}
			} else {
				if (((HashSet)object)!=null && (((HashSet)object).isEmpty() || ((HashSet)object).size()<=0)) {
					object = new LotOfCtxEl((HashSet)object);//we have no User... (getUsers).
				} else {
					logger.trace("It's a null or empty HashSet. using LotOfCtxEl. ??????????????");
					object = new UniqueCtxEl((HashSet)object);//LotOfCtxEl is wrong
				}
			}
		}
		logger.debug(AUPLog.LOG_MSG_END);
		return object;
	}
 
}
                                              
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:

Select allOpen in new window

 

by: ramazanyichPosted on 2008-01-28 at 02:06:47ID: 20757881

to check that it is not a problem with Corrector class, could you  comment out call to corrector.correct() api call ?


By the way could you say which version of betwext do you use ?
As i see from release notes at version 0.8 was some fixes for outofmemory problems. So if you use previous version try to download latest version of betwext and try it.

 

by: spice_stellinaPosted on 2008-01-28 at 02:29:28ID: 20757974

Thanks for support :-)
I commented those lines and magically all was de-allocated... :-)
I'm using betwixt-0.7.... and trying to download last release of betwixt ;-)

Anna

 

by: spice_stellinaPosted on 2008-01-28 at 03:26:15ID: 20758191

ramazanyich .... it works!! Thanks a lot! Changing library from betwixt-0.7 to betwixt-0.8 solved my problems! :-)

Thanks also to vinscom,
which has suggested useful parameters (from that suggestion, I googled and found more info about that and other parameters which were really useful for my tests) ;-)

I'll prepare another post, in which I'll put (I hope) some useful info about how we getted (to get)  this working situation (jboss-AS-4.0.5.ga+mysql5.0.24+stateless session EJB2.X+hibernate3+...+betwixt)  ;-)

Thanks a lot,
Anna

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...