lundi 2 mars 2015

hibernate + named query not known

I am getting problem while using named query with hibernate and spring.


below is my code and stacktrace.


Method that is calling my query is :



@SuppressWarnings("unchecked")
@Override
public List<CampaignEntity> getCampaignList() {
final Query clientQuery = getNamedQuery(CampaignEntity.GET_CAMPAIGNS_QUERY);
return (List<CampaignEntity>) clientQuery.list();
}


my Entity class is



package com.nativeunlock.dto;

import java.io.Serializable;

import javax.persistence.*;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;


@SuppressWarnings("serial")
@NamedQueries({
@NamedQuery(
name = CampaignEntity.GET_CAMPAIGNS_QUERY,
query = "from CampaignEntity campaign"
)
})

@Entity
@Data
@Table(name = "campaign")
public class CampaignEntity implements Serializable {

public static final String GET_CAMPAIGNS_QUERY ="getCampaignList";

@Id
@Getter
@Setter
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "campaingn_id", unique = true, nullable = false)
private int campain_id;


@Getter
@Setter
@Column(name = "no_of_views")
private int no_of_views;


@Getter
@Setter
@Column(name = "video_url")
private int video_url;

}


my xml file is



<beans xmlns="http://ift.tt/GArMu6"
xmlns:context="http://ift.tt/GArMu7"
xmlns:security="http://ift.tt/1c8inpe"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/GArMu6 http://ift.tt/1jdM0fG
http://ift.tt/GArMu7 http://ift.tt/1jdLYo7
http://ift.tt/1c8inpe http://ift.tt/18sW2ay">

<context:component-scan base-package="com.nativeunlock.**" />

<context:property-placeholder location="classpath:common.properties" />

<bean id="dataSource" class="${datasource.class}">
<property name="driverClassName" value="${mysql.driver}" />
<property name="url" value="${mysql.url}" />
<property name="username" value="${mysql.username}" />
<property name="password" value="${mysql.password}" />
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.nativeunlock.dao.**"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.connection.characterEncoding">UTF-8</prop>
<prop key="hibernate.connection.useUnicode">true</prop>
</props>
</property>
</bean>

<bean id="txManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="persistenceExceptionTranslationPostProcessor"
class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />


<bean id="savedRequestAwareAuthenticationSuccessHandler"
class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">
<property name="targetUrlParameter" value="targetUrl" />
</bean>


<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/pages/" />
<property name="suffix" value=".jsp" />
</bean>

<security:global-method-security
jsr250-annotations="enabled" pre-post-annotations="enabled"
secured-annotations="enabled" />

</beans>


my stacktrace is



org.hibernate.MappingException: Named query not known: getCampaignList
at org.hibernate.internal.AbstractSessionImpl.getNamedQuery(AbstractSess
ionImpl.java:154)
at org.hibernate.internal.SessionImpl.getNamedQuery(SessionImpl.java:137
1)
at com.nativeunlock.dao.CampaignDao.getNamedQuery(CampaignDao.java:41)
at com.nativeunlock.dao.CampaignDao.getCampaignList(CampaignDao.java:47)

at com.nativeunlock.service.CampaignService.getCampaignList(CampaignServ
ice.java:20)
at com.nativeunlock.security.controller.LoginController.campaign(LoginCo
ntroller.java:31)
at com.nativeunlock.security.controller.LoginController$$FastClassByCGLI
B$$25d5f75b.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocatio
n.invokeJoinpoint(Cglib2AopProxy.java:689)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:150)
at org.springframework.security.access.intercept.aopalliance.MethodSecur
ityInterceptor.invoke(MethodSecurityInterceptor.java:64)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterc
eptor.intercept(Cglib2AopProxy.java:622)
at com.nativeunlock.security.controller.LoginController$$EnhancerByCGLIB
$$ac304978_2.campaign(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.
invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandle
rAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandle
rAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(Dispatch
erServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(Dispatche
rServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(Frame
workServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServl
et.java:778)


Can any one help me to find out what wrong am I doing?


Aucun commentaire:

Enregistrer un commentaire