简体   繁体   中英

How do I specify the schema in EclipseLink JPQL query?

When I execute the query below I get the exception thereafter. How do I specify the schema in a JPQL query. My database schema is public. The database is PostgreSQL.

Here is my query:

SELECT p FROM profile p WHERE p.mobile_no = :mobileNo

Here is the exception:

java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
Exception Description: Problem compiling [SELECT p FROM profile p WHERE p.mobile_no = :mobileNo]. 
[14, 21] The abstract schema type 'profile' is unknown.
[30, 41] The state field path 'p.mobile_no' cannot be resolved to a valid type.
    org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1746)
    org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1767)
    za.co.ezimax.database.ProfileDAO.get(ProfileDAO.java:15)
    za.co.ezimax.business.Business.register(Business.java:44)
    za.co.ezimax.rest.DatabaseTestServlet.doGet(DatabaseTestServlet.java:87)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

How do I specify the schema in a JPQL query?

The schema configuration doesn't below to the query itself. It's configured in the datasource.

Keep in mind you are actually writing JPQL (and not SQL ). So you write queries against entities and not against tables. Having said that, you are expected to use the entity name and the entity fields instead of table names and table columns.

Instead of profile , you should use Profile (capital P ):

SELECT p FROM Profile p WHERE p.mobile_no = :mobileNo

Also ensure that mobile_no is the name of the field in your Profile entity (and not the name of the column in your database table).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM