org.hibernate.MappingException: Named query not known: Test.findByXXX after migrating from JBoss EAP 5 to JBoss EAP 6.3.3.

Solution Verified - Updated -

Issue

  • Within the JBoss EAP 6.3.3 migration from JBoss EAP 5, we changed the hibernate archives (.har) to JAP archives (.jar with a persistence.xml inside). This works fine, having an .EAR file with the application and inside one .jar file with the hibernate classes, mappings and the persistence.xml. This file is named within the application.xml as module and is entered within the .ear file on the top level.

  • This works fine, but the problem is:We have a second one, which is build within another project. This second jar file is entered within the application.xml and put into the top level of the .ear file too. The ear is deployed, and the PU is deployed too, but when we trigger an EJB on the server it results in following error:

Caused by: org.hibernate.MappingException: Named query not known: Test.findByXXX
    at org.hibernate.internal.AbstractSessionImpl.getNamedQuery(AbstractSessionImpl.java:155) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
    at org.hibernate.internal.SessionImpl.getNamedQuery(SessionImpl.java:1296) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
    at TsetDAOHibernate$1.test(TestDAOHibernate.java:33) [Tset.jar:$Name:  $]
  • The Named Query is defined in the hbm files of the Test.jar

  • Both persistence XMLs are:

The one with the named query not found.

<?xml version="1.0" encoding="UTF-8"?>  
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">  
  <persistence-unit name="tset_PU1">  
    <description>JPA Application1</description>  
    <jta-data-source>java:jboss/datasources/testDS1</jta-data-source>

    <properties> 
        <property name="hibernate.hbm2ddl.auto" value="validate"/>  
        <property name="hibernate.session_factory_name" value="java:/hibernate/testSessionFactory"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect"/>  

        <!-- Cache Options -->
        <property name="hibernate.cache.region_prefix" value=""/>
        <property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"/>
        <property name="hibernate.cache.use_query_cache" value="true"/>
        <property name="hibernate.cache.use_second_level_cache" value="true"/>

        <!-- DB Options -->
        <property name="hibernate.default_schema" value="test"/>

        <!-- Uncritical Options -->
        <property name="hibernate.format_sql" value="false"/>
        <property name="hibernate.jdbc.batch_size" value="20"/>
        <property name="hibernate.show_sql" value="false"/>
    </properties>  
  </persistence-unit>  
</persistence> 

The one with the named query found

<?xml version="1.0" encoding="UTF-8"?>  
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">  
  <persistence-unit name="test_PU2">  
    <description>JPA Application2</description>  
    <jta-data-source>java:jboss/datasources/testDS2</jta-data-source>
    <properties>  
        <property name="hibernate.hbm2ddl.auto" value="validate"/>  
        <property name="hibernate.session_factory_name" value="java:/hibernate/testSessionFactory"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect"/>  

        <!-- Cache Options -->
        <property name="hibernate.cache.region_prefix" value=""/>
        <property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"/>
        <property name="hibernate.cache.use_query_cache" value="true"/>
        <property name="hibernate.cache.use_second_level_cache" value="true"/>

        <!-- DB Options -->
        <property name="hibernate.default_schema" value="test"/>

        <!-- Uncritical Options -->
        <property name="hibernate.format_sql" value="false"/>
        <property name="hibernate.jdbc.batch_size" value="20"/>
        <property name="hibernate.show_sql" value="false"/>

    </properties>  
  </persistence-unit>  
</persistence>  
  • The log from, both PUs:
11:23:00,820 DEBUG [org.hibernate.ejb.Ejb3Configuration] (ServerService Thread Pool -- 52) Processing PersistenceUnitInfo [
    name: testPU1
    persistence provider classname: org.hibernate.ejb.HibernatePersistence
    classloader: ModuleClassLoader for Module "deployment.test.ear.test.jar:main" from Service Module Loader
    Temporary classloader: org.jboss.as.jpa.classloader.TempClassLoader@70fc0f11
    excludeUnlistedClasses: false
    JTA datasource: org.jboss.jca.adapters.jdbc.WrapperDataSource@6c1c9411
    Non JTA datasource: null
    Transaction type: JTA
    PU root URL: /AppServer/standalone/EAP-6.3/bin/content/test.ear/test.jar/
    Shared Cache Mode: UNSPECIFIED
    Validation Mode: AUTO
    Jar files URLs []
    Managed classes names []
    Mapping files names []
    Properties [
        hibernate.default_schema: sbtownr
        hibernate.cache.provider_class: net.sf.ehcache.hibernate.SingletonEhCacheProvider
        hibernate.cache.use_query_cache: true
        hibernate.dialect: org.hibernate.dialect.DB2Dialect
        hibernate.cache.use_second_level_cache: true
        hibernate.format_sql: false
        hibernate.cache.region.factory_class: org.jboss.as.jpa.hibernate4.infinispan.SharedInfinispanRegionFactory
        hibernate.jdbc.batch_size: 20
        hibernate.session_factory_name: java:/hibernate/sbterminalSessionFactory
        hibernate.cache.region_prefix: 
        hibernate.hbm2ddl.auto: validate
        hibernate.cache.infinispan.container: hibernate
        hibernate.show_sql: false]

11:23:00,820 DEBUG [org.hibernate.ejb.Ejb3Configuration] (ServerService Thread Pool -- 53) Processing PersistenceUnitInfo [
    name: testPU2
    persistence provider classname: org.hibernate.ejb.HibernatePersistence
    classloader: ModuleClassLoader for Module "deployment.test.ear.test.jar:main" from Service Module Loader
    Temporary classloader: org.jboss.as.jpa.classloader.TempClassLoader@1a0ca036
    excludeUnlistedClasses: false
    JTA datasource: org.jboss.jca.adapters.jdbc.WrapperDataSource@6c1c9411
    Non JTA datasource: null
    Transaction type: JTA
    PU root URL: vfs:/D:/Entwicklung/AppServer/standalone/SBT-EAP-6.3/bin/content/sbterminalBackendAPP.ear/PropertiesService.jar/
    Shared Cache Mode: UNSPECIFIED
    Validation Mode: AUTO
    Jar files URLs []
    Managed classes names []
    Mapping files names []
    Properties [
        hibernate.default_schema: sbtownr
        hibernate.cache.provider_class: net.sf.ehcache.hibernate.SingletonEhCacheProvider
        hibernate.cache.use_query_cache: true
        hibernate.dialect: org.hibernate.dialect.DB2Dialect
        hibernate.cache.use_second_level_cache: true
        hibernate.format_sql: false
        hibernate.cache.region.factory_class: org.jboss.as.jpa.hibernate4.infinispan.SharedInfinispanRegionFactory
        hibernate.jdbc.batch_size: 20
        hibernate.session_factory_name: java:/hibernate/sbterminalSessionFactory
        hibernate.cache.region_prefix: 
        hibernate.hbm2ddl.auto: validate
        hibernate.cache.infinispan.container: hibernate
        hibernate.show_sql: false]

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.3.3

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.