Running JPA entity with native queries from TestNG [message #1403754] |
Fri, 25 July 2014 23:09 |
supraja jayakumar Messages: 1 Registered: July 2014 |
Junior Member |
|
|
Hi All
I have an entity that has a native query like follows:
@Entity
@SqlResultSetMapping(name = "userMapping", entities=@EntityResult(entityClass = User.class))
@NamedNativeQuery(name = "User.query", query = "-- native query here --", resultSetMapping = "userMapping")
public class User {
}
Note that this entity does not have a table name and so there is no User table in the database. This entity was created simply for joining multiple tables quickly when we knew that the resultSet size will be high and so we decided to use native queries instead.
I am trying to test a method (with TestNG) that invokes this query like:
entityManager.createNamedQuery("User.query");
Of course, for purposes of testing, I create a separate entity manager container using the javax.persistence.EntityManagerFactory
But all named queries execute except this one. I turned on "useNativeSQL" in my persistence.properties. I am using eclipselink. But it does not execute and complains of:
ORA-942 Table or view does not exist.
While this is a normal exception considering that the "User" table is not there in the database (and I do not have permissions to create a table in the database!), I'd like to know if there is a workaround to overcome this exception. We definitely want to use only native queries here. But testing this code seems to be a problem.
Kindly help.
Thanks
|
|
|
Powered by
FUDForum. Page generated in 0.03518 seconds