It's not a secret anymore!
The moose likes Object Relational Mapping and the fly likes org.hibernate.HibernateException: Errors in named queries Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "org.hibernate.HibernateException: Errors in named queries" Watch "org.hibernate.HibernateException: Errors in named queries" New topic

org.hibernate.HibernateException: Errors in named queries

surendra harikantra

Joined: Jan 13, 2009
Posts: 4
Im using JPA with hibernate. Im able to insert record into db using JPA.
when im trying retrieve record from DB using NamedQuery, im getting javax.persistence.PersistenceException: [PersistenceUnit: wsrdatabase] Unable to build EntityManagerFactory
Am i missing something? please help me in that.
Entity bean:
@Table(name = "employee")
@NamedQueries( {
@NamedQuery(name = "employee.findAll", query = "SELECT e FROM employee e"),
@NamedQuery(name = "employee.byId",
query = "SELECT e FROM employee e WHERE e.employeeNum = :empNum") })

public class Employee

@Column(name = "employeeNum", nullable = false, unique = true)
private String employeeNum;

@Column(name = "firstName", nullable = false, unique = false)
private String firstName;
// class using entity bean
public List<Employee> searchAllEmployee() throws EmployeeException
EntityManagerFactory entityManagerFactory = Persistence.
createEntityManagerFactory( Constants.PERSISTENCE_UNIT );
EntityManager entityManager = entityManagerFactory.createEntityManager();
Query findAllQuery = entityManager.createNamedQuery("employee.findAll");
List<Employee> employees = findAllQuery.getResultList();
return employees;
<persistence-unit name="wsrdatabase">

<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost/wsrdatabase" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password" value="" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />

<property name="hibernate.connection.pool_size" value="6" />
<property name="hibernate.connection.autoReconnect" value="true" />
<property name="hibernate.generate_statistics" value="false" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.use_sql_comments" value="false" />
<property name="" value="update" />

Full stack trace of exception that occured:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
[PersistenceUnit: wsrdatabase] Unable to build EntityManagerFactory
javax.persistence.PersistenceException: [PersistenceUnit: wsrdatabase] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(
at javax.persistence.Persistence.createEntityManagerFactory(
at javax.persistence.Persistence.createEntityManagerFactory(
at com.wipro.sms.wsr.employee.EmployeeServiceImpl.searchAllEmployee(
at com.wipro.sms.wsr.employee.EmployeeServiceTest.testSearchAllEmployee(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(
at junit.framework.TestCase.runBare(
at junit.framework.TestResult$1.protect(
at junit.framework.TestResult.runProtected(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
Caused by: org.hibernate.HibernateException: Errors in named queries: employee.findAll, employee.byId
at org.hibernate.impl.SessionFactoryImpl.<init>(
at org.hibernate.cfg.Configuration.buildSessionFactory(
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(
... 21 more
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
try using

@NamedQuery(name = "employee.findAll", query = "SELECT e FROM Employee e"),

Employee instead of employee
surendra harikantra

Joined: Jan 13, 2009
Posts: 4
Thanks a lot buddy it is working now. :lol:
I agree. Here's the link:
subject: org.hibernate.HibernateException: Errors in named queries
It's not a secret anymore!