Hello,
Context:
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:
@Entity
public class User {
@Id
@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
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!
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.
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.
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:
To:
Hope that this helps and let me know how it goes!
Best,
Bobby