hildich kilal

Ranch Hand
+ Follow
since Aug 25, 2008
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by hildich kilal

I am facing an issue with FixedThreadPoolExecutor.

So scenario is that I need to load some data in cache from database. For this I run JDBC queries in database.
Now I need to run those queries in parallel . To get all data quickly.

I start an "newFixedThreadPool" executorService and there is one "Callable" class , say 'X' whose "call" method makes JDBC connection and executes select
I run a loop of around 5000 and create a new 'X' and submit it to executorService.
Now what i find is that even though I set pool size to some thing say 20 , I can see more than 100 -200 connections made in DB!

I have checked that I am closing connection properly . Also no other process is making any connection.

Is there a way this executorService can do that? The connection is made in "call" and closed there only.

Please suggest

FOllowing is the way you can use JTA in persistence unit

Make sure that you use a JTA data source with this persistence unit. You can define data source in a separate properties file or define it in persistence.xml iteself. Look for persistence.xml documentation to see how to use data source with hibernate.


debraj mallick wrote:hi hildich kilal,

did you got the any solution?

Hello Debraj,
Following are my findings after some research and readings

So few questions I have are

1) can we use JTA and Non - Jta transactions using same persistenceUnit?

No . We can not use JTA and Non JTA transactions in same PersistenceUnit. We need to create separate Persistence Unit. in J2SE application you can simply use to create entity manager factory but not in a J2EE. In an EE container you need to inject EntityManager using Container's injection mechanisms.

2) Do I need to define a JTA data source in JTA transaction?

Yes you need to use JTA data source in JTA transaction. It helps to avoid unnecessary connection pooling handling. In fact it is strongly advisable to use Data sources (or connection pooling apps like c3p0) in non jta applications also. I did use c3p0 / Data source from Weblogic successfully to resolve connection out of limit issue in my non JTA application recently.

Hope it helps
You can handle exception in Stored procedure (in EXCEPTION block) assign the error code and error message to two variables. Set these variables as OUT parameters in your stored procedure.

Read them after execute. This way SQLException will not be thrown.

Hope this helps.
This is the right way you call stored proc from hibernate.
Are you not getting error code in SQLException object? What exactly is your requirement?

Hello ,
We have a project which is using JPA (over hibernate). We are using Weblogic 11g application server.
Now till now we were using non -jta transaction throughout our application. All jdbc action was being done in DAO classes , using persistencemanager.

There is a requirement to use JTA at some places where we need to execute JDBC, JMS and some cache updates in one global transactions. For this we need to use JTA now.

So few questions I have are
1) can we use JTA and Non - Jta transactions using same persistenceUnit?
2) Do I need to define a JTA data source in JTA transaction?
3) To use JTA transaction in this case is following good enough
- Define hibernate.transaction.factory_class=org.hibernate.transaction.JTATransactionFactory
- Use JNDI to get UserTransactions and begin and commit it.
- create XA resources for hibernate and JMS between these.
How will Hibernate or JMS code will know that we need to associate the transaction with a global user transaction in this case?
Code I have is as follows

My persistence.xml looks like following

my jpa.properties looks like following

where MyDS is a non JTA data source defined in my weblogic server.

Also we have own classes to create PersistenceManager by parsing the persistence.xml and using persistenceUnitInfo classes.

Any pointers regarding this will be really helpful.

Hildich K
I have found the solution of # 3- We can define a datasource in Weblogic server (or JBoss or other server) and use it in out standalone Java code which is using Hibernate.
The configuration would be as follows to use DataSource .

That's it !! I have created a data source in my local Weblogic with jndi name of java/MyDS. Only point to note is that you should have wlfullclient.jar in your classpath to read the WLInitialContextFactory.

I am still looking for a way to define datasource in a java program !!? Or is it not possible to use DataSource outside a web/ejb container?


I have a need to use connection pooling to manage connection. My application at the moment keeps creating connections for hibernate operations. We are closing connections after every DB operation. but as application is a standalone java code which runs multiple threads after a period the connection crosses the limit.

I have 2 queries
1) I tried using

but still connections goes out of maximum limit? Why doesn't hibernate's in built pooling mechanism respect this count.

2) My second query is is there any other connection pooling tool than c3p0?
3) As my application is a standalone java program, I won;t be able to use DataSource feature to get connections.. Is this understanding correct?
I believe to use DataSource the code has to be run inside an app server or web server where data source can be configured in a ejb.xml or web.xml deployment file.
Or is there a way to use a data source defined in some Weblogic / JBoss server on a different machine , in my java standalone program?

Please let me know.


I have a requirement where I have a standalone java program which will run daily at around 11 PM. Now my code (which runs daily at 11 PM) has following logic.
- Connect to JMS
- Start listening asynchronously on the queues. (using MessageListener)

Once I am done getting all messages I properly close / shut down all JMS connections, listeners etc.

Now here is the issue.
The other program which puts the messages on queue can start before 11 PM. So whats happening is that the messages which came before my program started , are never fetched by my code. They remain on Queue forever.

I read about durable consumers also but it looks like I have to mandatory start listening , register as durable consumer, before I can get such missed messages.

Any pointers how to handle this scenario?

Thanks James,
That clarified my doubt. I am not using any connection pooling or any cache. I believe when you said cache you meant second level cache only?

In our application we are using a third party framework which creates its own EntityManagerFactory using some xyz-persistence.xml . The framework has its own classes to parse this xml and use EJB3Configuration class to create and EntityManagerFactory.

Now we dont want to use this. So what we have decided is to use simple default way to create EntityManagerFactory (using Persistence.createEntityManagerFactory which will read default persistence.xml in classpath)

Now both my application jar and other framework jar work in parallel.

So my question is can we create two different EntityManagerFactory pointing to same DB in one application? Can there be any issues , problems persistence managers from two EntitymanagerFactories start working parallel on same entity?

Please advise

I am confused between how a message consumer differs from message listener.
So I understand messageListener is for asynchronous messaging. We create a message consumer and then
set messageListener on it.

So usually when i create separate MessageConsumer and explicitely set a message Listener to them then it means
that there are many consumers but one Listener only listening on queue. But how does it help? Because the logic
to handle a message is still at one place? How will creating multiple consumers with same listener helps?

If I have a class which implements Messagelistener and then creates a messageConsumer inside it and
uses setMessagListener(this) to register listener . some thing like following

Now if I create multilpe instances of this class and call start() on them does that mean that now there are
multiple listeners listening on the queue?


robin patel wrote:Can you try keeping you JARS inside Domain/lib folder?
WebLogic follows dictionary level implementation when it comes to picking up the JARS.

Thanks Robin, I will try that and update the forum.

12 years ago

Wouter Oet wrote:How do you get the Role in your example?

Role is get as a (collection) of entities and populated in GUI. There it is just a POJO as it is out of PersistenceContext.
After user selects a particular role from select list it is passed as it is a Pojo in DAO. Primary key of Role is 'Name'.

My understanding is that as soon as i add this role in the the role should also get merged. But that is not happening.
I tried merging the Role explicitely. But then I get NonUniqueObject exception at time of commit.

here is the code from DAO

We have a situation where there are two classes with exactly same package structure in two different jars.
Now in local and Dev environements (luckily) correct jar is picked first and class loaded correctly.
But in QA weblogic server jars are not picked up in same order.

I would like to know how can I make sure that 2 jars are accessed in a particular order?

I had looked into <classloader-structure> also but couldn't understand much.

So I have 2 jars a.jar and b.jar and I always want to pick a class from a.jar .

Any pointers will be helpful.

12 years ago