Hi all...
I am pretty new to hibernate but I have made a sincere endeavour to find the source of my problem and have looked up in the FAQ's and the said documentation and did a search on previous postings but couldnt find any answers.
I am getting this exception org.hibernate.MappingException: Named query not known:
I have my named query in the following class: I was told that I wont need to manually edit any mapping files and hibernate takes care of them with XDoclet. We also have a ant script which deploys the code after any changes.
Do I still have to manually edit the hibernate mapping file, if so where can I find it as I couldnt find any file matching the pattern *hbm.xml in my deploy directory or workspace. I connect to the database through jboss.
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@Table(name="pg_shadow")
@NamedQueries({
@NamedQuery(name="selectPasswordByUsername",
query="select auth.password from "+
" com.mycompany.proj.collectable.persistence.mapped.PersistentAuthenticationData auth " +
" where auth.userName = :userName"),
@NamedQuery(name="selectRolename",
query="select auth.userName from "+
" com.mycompany.proj.collectable.persistence.mapped.PersistentAuthenticationData auth " +
" where auth.userName = :userName")
})
public class PersistentAuthenticationData {
/**
* Query name to select rolename <br>
* <code>QUERY_NAME_SELECT_ROLENAME</code>
*/
public static final String QUERY_NAME_SELECT_ROLENAME = "selectRolename";
/**
* Query name to select password by username <br>
* <code>QUERY_NAME_SELECT_PASSWD_BY_USERNAME</code>
*/
public static final String QUERY_NAME_SELECT_PASSWD_BY_USERNAME = "selectPasswordByUsername";
/**
* Prepared statement parameter name for user name
* <code>QUERY_PARAM_USERNAME</code>
*/
public static final String QUERY_PARAM_USERNAME = "userName";
/**
* user name <code>userName</code>
*/
private String userName;
/**
* password <code>password</code>
*/
private String password;
/**
* @return returns the user name
*/
@Column(name="usename")
public String getUsername() {
return userName;
}
/**
* @return returns the password
*/
@Column(name="passwd")
public String getPassword() {
return password;
}
/**
* @param userName user name
*/
public void setUsername(String userName) {
this.userName = userName;
}
}
Hibernate version:
3.1.2
Mapping documents:
Code between sessionFactory.openSession() and session.close():
public String getPassword(String userName, Session session) {
String password = null;
try {
Query query = session.getNamedQuery(PersistentAuthenticationData.QUERY_NAME_SELECT_PASSWD_BY_USERNAME);
query.setString(PersistentAuthenticationData.QUERY_PARAM_USERNAME, userName);
List<PersistentAuthenticationData> passwordList = query.list();
// If there is some thing in the password list returned by query, get the password else return null
password = (passwordList.size() > 0) ? passwordList.get(0).getPassword() : null;
}
catch(HibernateException he) {
LOGGER.getLogger(NoStackTraceLogFilter.STACK_TRACE_LOGGER_NAME).log(Level.SEVERE, StackTraceToStringer.doIt(he));
LOGGER.log(Level.INFO, "Cannot retreive password for user: " + userName);
}
return password;
}
Full stack trace of any exception that occurs:
SEVERE: org.hibernate.MappingException: Named query not known: selectPasswordByUsername
at org.hibernate.impl.AbstractSessionImpl.getNamedQuery(AbstractSessionImpl.java:71)
at org.hibernate.impl.SessionImpl.getNamedQuery(SessionImpl.java:1245)
at com.mycompany.proj.collectable.persistence.dao.AuthenticationDataDAO.getPassword(AuthenticationDataDAO.java:95)
at com.mycompany.proj.collectable.persistence.dao.AuthenticationDataDAO.getPassword(AuthenticationDataDAO.java:82)
at com.mycompany.proj.services.AuthenticateUserSrvc.getStoredPassword(AuthenticateUserSrvc.java:86)
at com.mycompany.proj.services.AuthenticateUserSrvc.executeService(AuthenticateUserSrvc.java:59)
at com.company.framework.core.dispatchers.LocalDispatcher.dispatch(LocalDispatcher.java:34)
at com.company.framework.core.ejb.RemoteServiceDispatcherBean.execute(RemoteServiceDispatcherBean.java:130)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:51)
at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:105)
at org.jboss.ejb.plugins.AbstractTxInterceptorBMT.invokeNext(AbstractTxInterceptorBMT.java:153)
at org.jboss.ejb.plugins.TxInterceptorBMT.invoke(TxInterceptorBMT.java:62)
at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:130)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:139)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
at org.jboss.ejb.Container.invoke(Container.java:873)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:805)
at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:406)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
at sun.rmi.transport.Transport$1.run(Transport.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:595)
Name and version of the database you are using:
Postgresql 8.1
Any help to get me over this problem would be appreciated.
Thanks in anticipation.
|