-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Hibernate 3.5.3 inside Spring 3.0.3 fails to validate named queries on Tomcat 7.0.0-beta [SPR-7350] #12009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Juergen Hoeller commented This doesn't happen for simple JPA deployment on Tomcat 7.0.0, so I suppose it has to do with your named queries (since it is checkNamedQueries that is failing in your stacktrace). Anything special in your named queries, in particular with respect to a 'P' constant? Juergen |
Costin Leau commented JuergenZ, could you try the application with web-app_3_0.xsd but w/o the TomcatInstrumentableClassLoader activated? This will tell us whether the special Spring class loader does something fishy or if the problem lies somewhere else. |
Juergen Zimmermann commented Regarding "P": I'm having 2 entity classes in an inheritance hierarchy:
Regarding TomcatInstrumentableClassLoader, I made the 2 changes below and got this stacktrace: ... 1st change in META-INF/context.xml: <!-- 2nd change in my SpringConfig Java class:
// emfBean.setLoadTimeWeaver(loadTimeWeaver()); |
Juergen Zimmermann commented After uncommenting the named query above, then I can set version="3.0". This is the named query with the TYPE operator as of JPA 2.0. In class Privatkunde there is a discriminator value according to inheritance modelling. |
Juergen Zimmermann commented Why does this query work, when I set version="2.5" ? |
Juergen Hoeller commented In order to make things work without TomcatInstrumentableClassLoader, you would also need to get rid of that DefaultContextLoadTimeWeaver - which is probably registered by a context:load-time-weaver entry in a Spring config file somewhere. I don't think TomcatInstrumentableClassLoader is affecting the situation anyway though. This is rather an issue with Hibernate trying to load a class named 'P' and then Tomcat failing to parse that class name, throwing an exception other than ClassNotFoundException (which is the only one Hibernate is catching there). Spring is only doing the bootstrap but not really involved in that specific failure then. Juergen |
Juergen Hoeller commented I suppose the query works in 2.5 mode simply because Tomcat 7's JNDI resource lookup fallback (as indicated by the WARDirContext part in the stacktrace) only seems to kick in in Servlet 3.0 mode. I suppose that JNDI resource fallback is new in Tomcat 7, and for strict backwards compatibility, it is not being applied in Servlet 2.5 mode. Juergen |
Juergen Zimmermann commented Now I managed to switch off the TomcatInstrumentableClassLoader, and Tomcat can be started with the Spring app and version=3.0" in web.xml. Reading from the database works fine. BUT, I cannot create any object of the derived entity class. There is not any record in the log file. Switching back to version="2.5" makes everything work again... |
Juergen Zimmermann commented I forgot to mention: when I switched back to versoin="2.5", I also switched on TomcatInstrumentableClassLoader. |
Juergen Hoeller commented Hmm, so it looks like TomcatInstrumentableClassLoader is actually part of the problem here... Maybe we need to code its overridden findResourceInternal method more defensively; on the other hand, we're only really calling the standard Tomcat version of the method and applying some post-processing if a resource has been found. Costin, any chance that you could reproduce this locally, declaring some such named queries and causing them to break the bootstrapping with web.xml version="3.0"? Juergen |
Costin Leau commented I'll look into it. JuergenZ you mentioned that you still had some issues under tomcat 7 such as not being able to create objects? Could you be more specific? |
Costin Leau commented JuergenZ, could you try a different JPA provider? I've tried recreating the problem with Hibernate 3.5.3 but got into all sorts of XML validation issues such as this one: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5310 Hope this helps, |
Juergen Zimmermann commented OK, I'll try EclipseLink. However,
|
Juergen Zimmermann commented Regarding: "Could you be more specific?" After I removed the named query with the TYPE operator, then Tomcat 7 starts without any error message even with version=3.0". I can read persistent data being converted into Java objects (via Hibernate 3.5.3 and persistence.xml with JPA 2.0 entries). However, when I invoke a form to submit new data to become persistent, then the Java object inside JSF 2 (Mojarra 2.0.3) is constructed (I could see it in my log file). But when invoking EntityManager.persist() then nothing happens: no new record in the database, and no log record that anything didn't work. This is just the same effect, when no transaction is running, i.e. when |
Costin Leau commented JuergenZ, I've tried Hibernate 3.5.3 with a modified petclinic with the ltw enabled and I am unable to reproduce the problem. Could you try to isolate your mapping and then upload it to this issue. I've used the following mapping:
I've added a named query through XML as well and the application starts w/o a problem. Note that I've tried with and without Hibernate validator in the classpath.
Not sure what else to try.... |
Juergen Zimmermann commented In between I migrated to EclipseLink. When using version=3.0" I cannot insert data (resp. objects) into the database, when using version=2.5" everything works fine. Since I'm logging via SLF4J and EclipseLink is using j.u.l I've no log records. Therefore, I'll provide a simplified testcase, so that you can reproduce the issue. |
Juergen Zimmermann commented Attachment #1: WAR file containing class files and all JARs except Spring 3.0.3 and Hibernate 3.5.3 (because of max upload size). Dependant files for Hibernate and Spring are included. |
Juergen Zimmermann commented Attachment #2: ZIP file containing 2 maven projects: Database setup for Oracle, SQLServer or DB2 could also be provided if necessary. |
Juergen Zimmermann commented Attachment #3: Source code for Java and JSF 2 resp XHTML pages |
Juergen Zimmermann commented A few hints to run the WAR file:
log4j.appender.KONSOLE = org.apache.log4j.ConsoleAppender log4j.appender.LOGDATEI = org.apache.log4j.RollingFileAppender log4j.logger.org.apache.catalina = INFO log4j.logger.de.hska = TRACE |
Juergen Zimmermann commented I've re-written the testcase to make things easier for you:
Again I'll upload:
H2 is preconfigured (see src/META-INF/spring.properties in hska.zip resp. WEB-INF/classes/META-INF/spring.properties in hska-without...war) |
Costin Leau commented JuergenZ, I've been able to install the war (after some minor adjustments) and run the webapp just fine on my machine.
in persistence.xml and
in spring.properties (should be db.props). Additionally I've modified context.xml by removing the path attribute of the Context (as an optional step since my war name was different. I enabled validation just to make sure everything works and added log4j.properties for logging and everything still worked.
|
Costin Leau commented JuergenZ, you could try to experiment more - for example, try removing AspectJ out of the picture and see whether this makes a difference. Hope this helps, |
Juergen Zimmermann commented The stacktrace is coming after the log fragment you copied above. I reduced the testcase again, and uploaded the war (v3): No validation, HSQLDB in "mem" mode, no managed beans for JSF2/Mojarra, no Spring beans, no EL2 from Sun, aop:... removed from spring.xml, no META-INF/aop.xml. Could you give the WAR another try, and add:
This should be sufficient (additionally META-INF/context.xml should be updated if you change the war's name). |
Costin Leau commented JuergenZ, I've been finally able to reproduce your problem. However it doesn't seem to be caused by Spring but rather by Tomcat. I'll report this to the tomcat team and keep you updated. |
Juergen Hoeller commented Since this will be addressed in Tomcat 7.0.x according to our latest conversation with Mark Thomas, I'll close this issue from Spring's side. Juergen |
Juergen Zimmermann opened SPR-7350 and commented
When I change the version number in web.xml from "2.5" to "3.0" and "web-app_2_5.xsd" to "web-app_3_0.xsd", then I get this stacktrace:
2010-07-04 09:03:56,858 INFO org.apache.naming.resources.WARDirContext - The name [META-INF/resources//WEB-INF/classes/'P'.class] is not valid
javax.naming.InvalidNameException: META-INF/resources//WEB-INF/classes/'P'.class: close quote appears before end of component
at javax.naming.NameImpl.extractComp(NameImpl.java:129)
at javax.naming.NameImpl.<init>(NameImpl.java:267)
at javax.naming.CompositeName.<init>(CompositeName.java:214)
at org.apache.naming.resources.WARDirContext.doLookup(WARDirContext.java:200)
at org.apache.naming.resources.BaseDirContext.lookup(BaseDirContext.java:461)
at org.apache.naming.resources.BaseDirContext.lookup(BaseDirContext.java:469)
at org.apache.naming.resources.ProxyDirContext.lookup(ProxyDirContext.java:303)
at org.apache.catalina.loader.WebappClassLoader.findResourceInternal(WebappClassLoader.java:2816)
at org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader.findResourceInternal(TomcatInstrumentableClassLoader.java:113)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2677)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1137)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1631)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1509)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:187)
at org.hibernate.impl.SessionFactoryImpl.getImportedClassName(SessionFactoryImpl.java:888)
at org.hibernate.hql.ast.util.SessionFactoryHelper.findQueryableUsingImports(SessionFactoryHelper.java:132)
at org.hibernate.hql.ast.util.SessionFactoryHelper.findQueryableUsingImports(SessionFactoryHelper.java:120)
at org.hibernate.hql.ast.util.LiteralProcessor.processConstant(LiteralProcessor.java:108)
at org.hibernate.hql.ast.tree.IdentNode.resolve(IdentNode.java:140)
at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:117)
at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:113)
at org.hibernate.hql.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:867)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1323)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.inRhs(HqlSqlBaseWalker.java:4552)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4175)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1909)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:824)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:610)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:294)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:237)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:98)
at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:560)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:422)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1385)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:891)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1469)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1409)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:386)
at de.hska.util.SpringConfig.entityManagerFactory(SpringConfig.java:150)
at de.hska.util.SpringConfig$$EnhancerByCGLIB$$dcebb33e.CGLIB$entityManagerFactory$3(<generated>)
at de.hska.util.SpringConfig$$EnhancerByCGLIB$$dcebb33e$$FastClassByCGLIB$$d770316a.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:215)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:210)
at de.hska.util.SpringConfig$$EnhancerByCGLIB$$dcebb33e.entityManagerFactory(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:142)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:561)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:973)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:879)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findDefaultEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:529)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:495)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:656)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:629)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:338)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:574)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4323)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4771)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:138)
at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3493)
at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:413)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1158)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1340)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1349)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1349)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1329)
at java.lang.Thread.run(Thread.java:619)
Affects: 3.0.3
Attachments:
Issue Links:
The text was updated successfully, but these errors were encountered: