I am currently trying to setup a connection between my database and my application, running on k8s, all running on DigitalOcean. My database is accepting all incoming connections for testing purposes right now. That enables me to let my application run locally but still connect to my remote database via Hibernate.

Problem: Running locally is no problem at all - it runs queries without any problem. But when my k8s pod application tries to run queries, the following error comes up:

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped [SELECT c from User c WHERE c.email = :email]
	at org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:79)
	at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:220)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:144)
	at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:113)
	at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:73)
	at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:162)
	at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:622)
	at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:734)
	... 26 common frames omitted
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped
	at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:169)
	at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:91)
	at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:77)

A little snippet from my User class:

public class User {

    @GeneratedValue(strategy = GenerationType.AUTO, generator = "system-uuid")
    @Column(name = "id", nullable = false)
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    private String id;
    private String firstname;
    private String lastname;
    private String organizationID;
    private String email;
    private String password;
    private boolean isActivated;

My question: Why does it work locally and not in my pod? To me, it does not seem to have anything to do with the connection, or am I incorrect?

Thanks in advance, I hope to get an answer soon.

Kind regards, Alex

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
April 14, 2023

Hi there,

The issue seems to be related to the classpath or Hibernate configuration rather than the database connection.

When running your application in the Kubernetes pod, it might not be able to find the User class or load it properly.

Does this work if you start your application locally using the Docker image that you’ve built?

I believe that you need to ensure that the compiled classes and resources are properly included in the container image. Check the Dockerfile and make sure you are copying the compiled classes and resources to the correct location.

Another similar problem that I came across here also indicated that the problem was solved after changing the import line from:

import org.hibernate.annotations.Entity;


import javax.persistence.Entity;

Hope that this helps and let me know how it goes!



Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel