jQuery in Action, 2nd edition*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
Author

org.hibernate.HibernateException: Errors in named queries

surendra harikantra
Greenhorn

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:
@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
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
Greenhorn

Joined: Jan 13, 2009
Posts: 4
Thanks a lot buddy it is working now. :lol:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: org.hibernate.HibernateException: Errors in named queries
 
Similar Threads
PRO EJB 3.0: Junit tests
Please HELP! [EJB 3] - Could not find datasource in Eclipse/JBoss - SQLServer
Error creatigng EntityManagerFactory
org.hibernate.PropertyValueException: not-null property references a null or transient value:
HibernateException: Hibernate Dialect must be explicitly set