• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

org.hibernate.HibernateException: Errors in named queries

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
@Entity
@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
{

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

@Basic
@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.xml
<persistence-unit name="wsrdatabase">
<provider>org.hibernate.ejb.HibernatePersistence</provider>

<properties>
<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="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
</persistence>



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(Ejb3Configuration.java:677)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
at com.wipro.sms.wsr.employee.EmployeeServiceImpl.searchAllEmployee(EmployeeServiceImpl.java:122)
at com.wipro.sms.wsr.employee.EmployeeServiceTest.testSearchAllEmployee(EmployeeServiceTest.java:87)
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(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.hibernate.HibernateException: Errors in named queries: employee.findAll, employee.byId
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:397)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
... 21 more
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try using

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


Employee instead of employee
 
surendra harikantra
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot buddy it is working now. :lol:
reply
    Bookmark Topic Watch Topic
  • New Topic