【发布时间】:2015-06-19 04:33:33
【问题描述】:
我试图在我的数据库中调用 Terminal_GetTicket 存储过程,但不断收到以下异常:
PropertyReferenceException: No property getTicket found for type TicketInfo
我已经用一个非常简单的测试实体交叉验证了我的配置,一切似乎都运行良好,但是对于实际情况,出现了问题。
这是我的域实体 (TicketInfo):
@Entity
@NamedStoredProcedureQuery(name = "TicketInfo.getTicket", procedureName = "Terminal_GetTicket", resultClasses = TicketInfo.class, parameters = {
@StoredProcedureParameter(mode = ParameterMode.IN, name = "sys_id_game", type = Integer.class)})
public class TicketInfo {
@Id @GeneratedValue
private Long id;
private String idTicket;
private Integer externalTicketCode;
private Short sequenseAlert;
private Integer dlTimeStamp;
所有实例变量都有正确定义的getter和setter,存储过程共有5个输出参数匹配TicketInfo的属性。
此外,这是我的存储库界面:
public interface TicketInfoRepository extends CrudRepository<TicketInfo, Long> {
@Transactional(timeout = 5)
@Procedure
TicketInfo getTicket(Integer sys_id_game);
}
另外,这是我的 context.xml 文件(用于 Spring):
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:repository="http://www.springframework.org/schema/data/repository"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa-1.8.xsd
http://www.springframework.org/schema/data/repository
http://www.springframework.org/schema/data/repository/spring-repository-1.5.xsd">
<context:component-scan base-package="ar.com.boldt.godzilla" />
<jpa:repositories base-package="xx.xxx.xxx.godzilla.business.dao" />
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="${dataSource.show.sql}" />
<property name="generateDdl" value="false" />
<property name="database" value="SQL_SERVER" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<!-- spring based scanning for entity classes -->
<property name="packagesToScan" value="xx.xxx.xxx.godzilla.business.dao" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" />
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="ehcache" />
</bean>
<bean id="ehcache"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml" />
</bean>
</beans>
最后是存储过程本身的淡化版本:
ALTER PROCEDURE [Terminal_GetTicket](
@arg int
,@res int output
,@res2 int output
)
as
Declare @error int
select 0, 1, 2
RETURN @error
现在,每当我尝试设置 @Autowired 注释时,都会遇到上述异常。
【问题讨论】:
-
我以前从未这样做过,但是我有以下两个猜测(基于此链接[1]:似乎您可以通过设置@Procedure来显式设置存储过程的名称(name="TicketInfo.getTicket") 或者您可以将procedureName与您的方法名称对齐(Terminal_GetTicket vs getTicket)[1] github.com/spring-projects/spring-data-examples/tree/master/jpa/…
-
我按照你的建议更改了我的代码,我使用了 @Procedure(name = "TicketInfo.getTicket") ,但我得到了同样的错误。
标签: java jpa spring-data spring-data-jpa