These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: org.hibernate.HibernateException: Errors in named queries
PostPosted: Thu Jan 15, 2009 2:54 am 
Newbie

Joined: Tue Jan 13, 2009 1:52 am
Posts: 1
Hibernate version: 3

Mapping documents: JPA Annotations


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



Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2009 10:27 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
HQL is case-sensitive, so you have to write "... from Employee...".


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.