Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java spring中的ecache配置抛出:“0”;命名查询未知错误“;_Java_Spring_Hibernate_Spring Mvc_Hibernate Cache - Fatal编程技术网

Java spring中的ecache配置抛出:“0”;命名查询未知错误“;

Java spring中的ecache配置抛出:“0”;命名查询未知错误“;,java,spring,hibernate,spring-mvc,hibernate-cache,Java,Spring,Hibernate,Spring Mvc,Hibernate Cache,尝试在我的Spring应用程序中的Dao上运行单元测试 我得到错误:命名查询未知。 实际上,我正试图用Spring4.2实现缓存 以下是与集成相关的代码: 看看我的测试用例 我的测试课:问题测试 public class QuestionDaoTest extends BaseDaoTest { @Autowired private QuestionTypeDao questionTypeDaoImpl; private static final Logger logger =Log

尝试在我的Spring应用程序中的Dao上运行单元测试 我得到错误:命名查询未知。 实际上,我正试图用Spring4.2实现缓存

以下是与集成相关的代码: 看看我的测试用例

我的测试课:问题测试

 public class QuestionDaoTest extends BaseDaoTest {

 @Autowired
 private QuestionTypeDao questionTypeDaoImpl;

 private static final Logger logger =LogManager.getLogger(QuestionDaoTest.class);

  @Test
  @Transactional
  public void test() {
  QuestionType questionType = 
    questionTypeDaoImpl.getQuestionTypeIdByName("Single Choice");
    logger.debug("Firing Query");
  }
}
我犯的错误

堆栈跟踪

  org.springframework.orm.hibernate4.HibernateSystemException: Named query not known: getQuestionTypeIdByName;
  nested exception is org.hibernate.MappingException: Named query not known: getQuestionTypeIdByName at org.springframework.orm.hibernate4
  .SessionFactoryUtils.convertHibernateAccessException
  (SessionFactoryUtils.java:218)at org.springframework.orm.hibernate4
  .HibernateExceptionTranslator.convertHibernateAccessException
  (HibernateExceptionTranslator.java:57)
Mydao context config.xml定义:

<context:component-scan base-package="com.oea.dao" />
<cache:annotation-driven />
<tx:annotation-driven transaction-manager="transactionManager" />

 <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" 
     p:cacheManager-ref="ehcache"/>

<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" 
     p:configLocation="classpath:ehcache.xml"  
     p:shared="true"/> 
我有一个我认为有效的ehcache.xml。。。 Myehcache.xml定义:

 <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
<!-- <defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" />
<cache name="employee" maxElementsInMemory="10000" eternal="true" overflowToDisk="false" /> -->
<diskStore path="java.io.tmpdir"/>
<cache name="person"
       maxElementsInMemory="100"
       eternal="false"
       timeToIdleSeconds="120"
       timeToLiveSeconds="120"
       overflowToDisk="true"
       maxElementsOnDisk="10000000"
       diskPersistent="false"
       diskExpiryThreadIntervalSeconds="120"
       memoryStoreEvictionPolicy="LRU"/>
有人知道我做错了什么吗?这似乎是一个相当直接的实现,它正在处理我所看到的所有教程,但由于某些原因,在执行测试时,我无法启动应用程序。 任何帮助都将不胜感激谢谢

 @NamedQueries({ @NamedQuery(name = "getQuestionTypeIdByName", query = "from 
 QuestionType qt where qt.questionType = :questionType ") })

 @Entity
 @Table(name = "question_type")
 public class QuestionType {}
 <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
<!-- <defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" />
<cache name="employee" maxElementsInMemory="10000" eternal="true" overflowToDisk="false" /> -->
<diskStore path="java.io.tmpdir"/>
<cache name="person"
       maxElementsInMemory="100"
       eternal="false"
       timeToIdleSeconds="120"
       timeToLiveSeconds="120"
       overflowToDisk="true"
       maxElementsOnDisk="10000000"
       diskPersistent="false"
       diskExpiryThreadIntervalSeconds="120"
       memoryStoreEvictionPolicy="LRU"/>
[main] INFO org.springframework.cache.ehcache.EhCacheManagerFactoryBean - 
Initializing EhCache CacheManager
[main] INFO org.springframework.test.context.transaction.TransactionContext 
- Began transaction (1) for test context [DefaultTestContext@4d654825 
testClass = QuestionDaoTest, testInstance = 
com.soe.dao.test.QuestionDaoTest@3bfc6a5e, testMethod = 
test@QuestionDaoTest, testException = [null], mergedContextConfiguration = 
[MergedContextConfiguration@23940f86 testClass = QuestionDaoTest, locations 
= '{classpath:/soe-dao-context-test.xml}', classes = '{}', 
contextInitializerClasses = '[]', activeProfiles = '{}', 
propertySourceLocations = '{}', propertySourceProperties = '{}', 
contextCustomizers = set[[empty]], contextLoader = 
'org.springframework.test.context.support.DelegatingSmartContextLoader', 
parent = [null]]]; transaction manager 
[org.springframework.orm.hibernate4.HibernateTransactionManager@7e94d093]; 
rollback [false]
[main] INFO org.springframework.test.context.transaction.TransactionContext 
- Committed transaction for test context [DefaultTestContext@4d654825 
testClass = QuestionDaoTest, testInstance = 
com.soe.dao.test.QuestionDaoTest@3bfc6a5e, testMethod = 
test@QuestionDaoTest, testException = 
org.springframework.orm.hibernate4.HibernateSystemException: Named query not 
known: getQuestionTypeIdByName; nested exception is 
org.hibernate.MappingException: Named query not known: 
getQuestionTypeIdByName, mergedContextConfiguration = 
[MergedContextConfiguration@23940f86 testClass = QuestionDaoTest, locations 
= '{classpath:/soe-dao-context-test.xml}', classes = '{}', 
contextInitializerClasses = '[]', activeProfiles = '{}', 
propertySourceLocations = '{}', propertySourceProperties = '{}', 
contextCustomizers = set[[empty]], contextLoader = 
'org.springframework.test.context.support.DelegatingSmartContextLoader', 
parent = [null]]].
[Thread-3] INFO 
org.springframework.context.support.GenericApplicationContext - Closing 
org.springframework.context.support.GenericApplicationContext@35841320: 
startup date [Thu Aug 03 11:37:56 IST 2017]; root of context hierarchy2017-
08-03 11:38:16,182 pool-1-thread-1 DEBUG Stopping 
LoggerContext[name=16b98e56, 
org.apache.logging.log4j.core.LoggerContext@2cb4893b]

2017-08-03 11:38:16,183 pool-1-thread-1 DEBUG Stopping 
LoggerContext[name=16b98e56, 
org.apache.logging.log4j.core.LoggerContext@2cb4893b]...
[Thread-3] INFO org.springframework.cache.ehcache.EhCacheManagerFactoryBean 
- Shutting down EhCache CacheManager
2017-08-03 11:38:16,187 pool-1-thread-1 DEBUG Shutting down 
RollingFileManager C:/src/personal/logs/monitor.log