Could not locate TransactionManager in HQL Console

I have the a project with JPA facet. JPA descriptor is linked to persistence.xml. The contents of my persistence xml are following:

org.hibernate.ejb.HibernatePersistence java:/myDatasource In project properties I have linked the persistence unit to a second datasource which I have created in IDEA via menu Tools/DataSources. Datasource is tested and has loaded tables. This datasource has different name then the datasource in persistence.xml. I open the HQL console and want to execute a select. I get the following errors: org.hibernate.HibernateException: Could not locate TransactionManager at org.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager( at org.hibernate.impl.SessionFactoryImpl.]]>(
at org.hibernate.cfg.Configuration.buildSessionFactory(
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(
at javax.naming.InitialContext.getDefaultInitCtx(
at javax.naming.InitialContext.getURLOrDefaultInitCtx(
at javax.naming.InitialContext.lookup(
at org.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager(
... 31 more

I think that transaction manager is already specified in persistence.xml. Any ideas?

Edited by: Steve Hickson on Aug 7, 2008 5:45 PM. Added HQlL console tag

Comment actions Permalink

FINALLY! I got the HQL Console running with JPA!

After some googling, documentation reading and more googling I found a solution for the above described problem.


1. You need sources of your entity classes with annotations to be existing in your IDEA module
2. In menu Tools/Datasources create datasource
3. The module must have JPA facet inside
4. You need persistence.xml file which must be referenced in JPA facet
5. In the facet the persistence unit must be mapped to your datasource

Get the console running

1. Add the database driver lib in your module dependency
2. Download Sun JNDI 1.2.1 from . Specifically you need to download File System Service Provider, 1.2 Beta 3
3. Put fscontext.jar and providerutil.jar from the Sun JNDI into your module dependency
4. Go to IDEA installation directory and open file bin/idea.exe.vmoptions
5. Add the following line: -Djava.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory and restart IDEA
6. The persistence.xml file which you have probably already contains some standard configuration properties. The following properties must be added to get it working:
7. Persistence unit must be resource local e.g. <persistence-unit name="myunit" transaction-type="RESOURCE_LOCAL">
8. Because the entity mapping autodetection is for some reason not working in HQL Console context all etity classes must be specified manually. Example:

<persistence-unit name="myunit" transaction-type="RESOURCE_LOCAL">

9. Add JNDI url. The /jndi corresponds to c:/jndi directory. Don't forget to create this directory. Of course you can specify any directory you want. Example:

<property name="hibernate.jndi.url" value="file:/jndi"/>

10. Add session factory JNDI. Example:

<property name="hibernate.session_factory_name" value="java:/hibernate/MySessionFactory"/>

11. The HQL Console is little bit hidden. To start it, go to project view, change the view as Java EE: Structure. Navigate to JPA facet, right click on your persistence unit name e.g. myunit and from menu select Open HQL Console.

Comment actions Permalink

And one bugreport:

In HQL Console there is Execute button. Tooltip says the shortcut is Ctrl+Insert.

1) This shortcut only selects all text but does not execute
2) What is the the shortcut to execute?

Comment actions Permalink

Hello Steve,

And one bugreport:

In HQL Console there is Execute button. Tooltip says the shortcut is

1) This shortcut only selects all text but does not execute 2) What is
the the shortcut to execute?

It's Ctrl+Enter. (And tooltip shows the same for me.)


Comment actions Permalink

Ahh of course Ctrl+Enter, thanks. I had a German Windows and I misinterpreted the tooltip. My fault, sorry.


Please sign in to leave a comment.