adaniluk
adaniluk

Reputation: 431

hibernate inheritance select from

I have question: Let's assume I have two classes User and Employee, Employee extends User, in User I have @Inheritance(strategy=InheritanceType.JOINED). Is it correct to get Employees in this way "FROM User p WHERE p.login = :login AND p.password = :password"; Login and password attributes are in User.

ERROR: org.hibernate.hql.internal.ast.QuerySyntaxException: USER is not mapped [FROM USER p WHERE p.login = :login AND p.password = :password]

Upvotes: 0

Views: 567

Answers (1)

JB Nizet
JB Nizet

Reputation: 691775

HQL uses class names and mapped attribute/properties names. Always. It doesn't use table and column names. Never. So, if your class is named User, as you initially said in the question and as it should be named to respect the Java naming convention, the query you asked for should work fine:

FROM User p WHERE p.login = :login AND p.password = :password

The exception says that the query, in fact, is

FROM USER p WHERE p.login = :login AND p.password = :password

which is invalid, as the exception says, because USER is not the name of a mapped entity class.

Also, note that the exception is not a NullPointerException, but a QuerySyntaxException.

Upvotes: 1

Related Questions