Results 1 to 3 of 3

Thread: Spring + Hibernate Problem mappingResources

  1. #1

    Default Spring + Hibernate Problem mappingResources

    spring-framework-3.1.1.RELEASE
    spring-security-3.1.0.RELEASE
    spring-flex-1.5.2.RELEASE
    hibernate-distribution-3.6.10.Final

    I am attempting to run some unit tests on my spring web app.

    app-config.xml
    Code:
    	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="mappingResources">
            	<value>com/crm/hibernate/mapping/resources/*.hbm.xml</value>
            </property>
    		<property name="dataSource" ref="dataSource"/>
    		<property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence"/>
    	 	<property name="packagesToScan" value="com.crm.model.entity" /> 
    	 </bean>
    My DAO method:
    Code:
    	@SuppressWarnings("unchecked")
    	public List<ProductModel> teste()throws DAOException{
    		return entityManager.createNamedQuery("hql.product.all").getResultList();
    	}
    HBM
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping >
        <query name="hql.product.all">from ProductModel</query>
    </hibernate-mapping>
    I recieve the error :

    Code:
    java.lang.IllegalArgumentException: Named query not found: hql.product.all
    	at org.hibernate.ejb.AbstractEntityManagerImpl.createNamedQuery(AbstractEntityManagerImpl.java:619)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at java.lang.reflect.Method.invoke(Method.java:597)

  2. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    Hello

    1) what is the name of your "HBM"
    2) where is located your "HBM"


    I am attempting to run some unit tests on my spring web app.
    3) Post the JUnit code (Test class) to see how you did the settings configurations.
    4) Post the complete error stack trace
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3

    Default

    1) name HBM: HQLProduct.hbm.xml
    2) located: com.crm.hibernate.mapping.resources

    3)
    Code:
    package com.crm.service.impl;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import org.junit.BeforeClass;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.test.annotation.Rollback;
    import org.springframework.test.context.ContextConfiguration;
    import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    import org.springframework.test.context.transaction.TransactionConfiguration;
    import org.springframework.transaction.annotation.Transactional;
    import org.springframework.util.Assert;
    
    import com.crm.exception.java.DAOException;
    import com.crm.model.entity.ProductModel;
    import com.crm.service.IProductService;
    
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration("app-test.xml")
    @TransactionConfiguration(defaultRollback=true)
    public class ProductTest {
    
    	@Autowired
    	IProductService service;
    
    	@Test
    	public void testFindAllProductModelsHBM()throws DAOException{
    		List<ProductModel>list= service.findAllProductModelsHBM();
    		Assert.isTrue(list.size()>0);
    	}
    }
    4) stack trace

    Code:
    java.lang.IllegalArgumentException: Named query not found: hql.product.all
    	at org.hibernate.ejb.AbstractEntityManagerImpl.createNamedQuery(AbstractEntityManagerImpl.java:619)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
    	at com.crm.dao.impl.ProductDAO.findAllProductModelsHBM(ProductDAO.java:89)
    	at com.crm.service.impl.ProductService.findAllProductModelsHBM(ProductService.java:44)
    	at com.crm.service.impl.ProductService$$FastClassByCGLIB$$a1a727c0.invoke(<generated>)
    	at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
    	at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:618)
    	at com.crm.service.impl.ProductService$$EnhancerByCGLIB$$3ee50a8f.findAllProductModelsHBM(<generated>)
    	at com.crm.service.impl.ProductTest.testFindAllProductModelsHBM(ProductTest.java:32)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
    	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
    	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    Observation: manual mapping runs no problems
    Code:
    	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="mappingResources">
    			<list>
    	        	<value>com/crm/hibernate/mapping/resources/HQLProduct.hbm.xml</value>
    	        </list>
            </property>
    I github for sending, if necessary.

    Quote Originally Posted by dr_pompeii View Post
    Hello

    1) what is the name of your "HBM"
    2) where is located your "HBM"



    3) Post the JUnit code (Test class) to see how you did the settings configurations.
    4) Post the complete error stack trace
    Last edited by silvanopessoa; Apr 15th, 2012 at 03:40 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •