Jump to content
We've recently updated our Privacy Statement, available here ×

Problem with Spring loaded Hibernate connection


robbr

Recommended Posts

 I have the applicationContext.xml on the classpath with the sessionFactory bean. I'm using annotations with Spring and Hibernate. Now when I test the connection I get a cryptic error: 

org.hibernate.hql.ast.QuerySyntaxException: unexpected token: Address near line 1, column 27 [select address as address Address as address]

The stack trace is absolutely no help, there is no "Caused By: " entry. Why is this statement even being executed? My Query text is blank. Even when I comment out all the mappings in my hibernate configuration file it tries to do this.
 
Thanks in advance I'm really stumped on this one.
Link to comment
Share on other sites

  • 3 months later...
  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • 2 years later...

I figured this out. You get this stupid error because of one sample query written in JRSpringLoadedHibernateConnection and developers of iReport forgot to include the mapping files.  You get this error when you click on test button of spring loaded hibernate connection. You can ignore this error message. I have pasted the complete definition of this method. You can make out easily from the below method that it is trying to create a sessionfactory. once you obtain a sessionfactory, it is trying to execute this sample query for which no mapping file is defined.

Even if you get this erros messgae click OK, save connection and proceed to use the connection. It works for me. I have verified this.

 public void test() throws Exception
        {
            try {
                    Thread.currentThread().setContextClassLoader( IReportManager.getInstance().getReportClassLoader() );
                   
                    SessionFactory sf = getSessionFactory();
                    if (sf == null) {
                            JOptionPane.showMessageDialog(Misc.getMainWindow(),
                                    //I18n.getString("messages.connectionDialog.noSessionFactoryReturned",
                                    "No session factory returned.  Check your session factory bean id against the spring configuration.",
                                    "Error",JOptionPane.ERROR_MESSAGE);
                    }
                    else
                    {
                       
                       
                            Session hb_session = sf.openSession();
                            Transaction  transaction = hb_session.beginTransaction();
                            Query q = hb_session.createQuery("select ");
                       
                            q.setFetchSize(1);
                            java.util.Iterator iterator = q.iterate();
                            // this is a stupid thing: iterator.next();

                            String[] aliases = q.getReturnAliases();
                            Type[] types = q.getReturnTypes();
               
                           
                        JOptionPane.showMessageDialog(Misc.getMainWindow(),
                                //I18n.getString("messages.connectionDialog.hibernateConnectionTestSuccessful",
                                "iReport successfully created a Hibernate session factory from your Spring configuration.",
                                "",JOptionPane.INFORMATION_MESSAGE);
                    }
            } catch (Exception e) {
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(Misc.getMainWindow(),e.getMessage(),
                            "Error",JOptionPane.ERROR_MESSAGE);

            }
        }

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...