DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Automatic Versioning in Mobile Apps
  • Live Database Migration
  • Schema Change Management Tools: A Practical Overview
  • Advanced Maintenance of a Multi-Database Citus Cluster With Flyway

Trending

  • Using LLMs to Automate Data Cleaning and Transformation Pipelines
  • Build a GitHub Slack Bot With AWS Bedrock and MCP, Part 2
  • Optimizing High-Volume REST APIs Using Redis Caching and Spring Boot (With Load Testing Code)
  • Zero-Downtime Deployments for Java Apps on Kubernetes
  1. DZone
  2. Data Engineering
  3. Databases
  4. JPA's Nasty "Unknown abstract schema type" Error

JPA's Nasty "Unknown abstract schema type" Error

By 
Khoo Chen Shiang user avatar
Khoo Chen Shiang
·
Jan. 13, 09 · Interview
Likes (0)
Comment
Save
Tweet
Share
54.0K Views

Join the DZone community and get the full member experience.

Join For Free
I'd been trying to debug the following error for days, and it drove me crazy. The problem, in a nutshell, is that JPA refuses to compile one of my NamedQueries, throwing the following error:

Error compiling the query [UserVO.findByUserName: SELECT u FROM UserVO u WHERE u.name = :name].
Unknown abstract schema type [UserVO]


After numerous Google searches, I concluded that JPA will throw the "Unknown abstract schema type"  error when JPA fails to locate your entity class.  Most often, this type of error occurs when:

  • You have provided the database table name instead of the entity class name in the JPA query. For example, if you have an entity class called "UserVO", which maps to the table name "users", the query "SELECT u from users u" will throw the above exception.

  • When running JPA in standalone mode, or not in a Java EE container (such as Tomcat 5 or 6), you forget to explicitly list all entity classes in the persistence.xml file, thus causing JPA to fail to locate the entities when compiling the query.


Neither of above applied to my case. I have explicitly listed all my entity classes in the persistence.xml and I am sure my JPA query is valid. I have tested my code with different JPA implementations, but always saw the same error.

Here's my UserVO class:
@Entity(name = "users")
@NamedQuery(name = "UserVO.findByUserName",
query = "SELECT u FROM UserVO u WHERE u.name = :name")
public class UserVO extends BaseVO implements Serializable {

...
...
}


If I remove the NamedQuery, my JPA works as expected, i.e, I am able to insert, delete, and update the UserVO object.

Now, to all my smart readers, can you spot what's wrong in my code? Think about it and then scroll down for the answer...

 

 

 

 

 

 

 

 

Answer: The culprit is the Entity annotation. I explicitly named the UserVO entity "users". JPA has no problem to map the UserVO entity to the users database table. However, JPA has a problem when compiling the JPA Query: it can't find the UserVO entity in the JPA context because I have renamed the UserVO entity to users.

To resolve this, just add a @Table annotation with the table name, as shown in the code below:
@Entity
@Table(name = "users")
@NamedQuery(name = "UserVO.findByUserName",
query = "SELECT u FROM UserVO u WHERE u.name = :name")
public class UserVO extends BaseVO implements Serializable {

...
...
}

Haha, stupid me... Anyway, Happy New Year to everyone.
Database Schema

Opinions expressed by DZone contributors are their own.

Related

  • Automatic Versioning in Mobile Apps
  • Live Database Migration
  • Schema Change Management Tools: A Practical Overview
  • Advanced Maintenance of a Multi-Database Citus Cluster With Flyway

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook