Hibernate Error - Querysyntaxexception: Users Is Not Mapped [From Users]

hibernate JPA error : org.hibernate.hql.internal.ast.QuerySyntaxException: users is not mapped

org.hibernate.hql.internal.ast.QuerySyntaxException: users is not
mapped

createQuery used to create JPQL. In JPQL, you should use the name of the Entity class instead of the name of the table. So use User instead of users in query

em.createQuery("SELECT u FROM User u WHERE u.username = :username AND u.password = :password", User.class);

org.hibernate.hql.internal.ast.QuerySyntaxException: table is not mapped

Finally I found a mistake! Hope this is useful to someone. When doing a request to the database(in my case it Apache Derby), name of base need write the first letter upper case other in lower case.

This is wrong query:

session.createQuery("select first_name from CUSTOMERV").

This is valid query

session.createQuery("select first_name from Customerv"). 

And class entity must be same name as database, but I'm not sure.

Hibernate QuerySyntaxException: Not Mapped

In Hibernate (and JPA), the mapping is to the class, that is, Notification. HQL works using your entity classes, and is case sensitive.

With this in mind, your HQL query

from notification where delete_timestamp IS NULL

Should be

from Notification where deleteTimestamp IS NULL
^ ^
|---> class |---> attribute in your class

Hibernate QuerySyntaxException Table is not mapped

Can you try this code for your sessionFactory. It helped me

final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.configure().build();
sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();

Turning Sonar off for certain code

This is a FAQ. You can put //NOSONAR at the end of the line triggering the warning.

//NOSONAR

For most languages, SonarQube supports the use of the generic mechanism: //NOSONAR at the end of the line of the issue. This will suppress all issues - now and in the future - that might be raised on the line.

I prefer using the FindBugs mechanism though, which consists in adding the @SuppressFBWarnings annotation:

@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
value = "NAME_OF_THE_FINDBUGS_RULE_TO_IGNORE",
justification = "Why you choose to ignore it")

SonarQube JavaScript disable a part of code

SonarQube provides plenty of options for ignoring issues in specific files and/or code blocks, see Narrowing the Focus documentation (and to your specific case: look for Ignore Issues in Blocks).



Related Topics



Leave a reply



Submit