No query defined for that name using Hibernate API
<p>I'm developing an application using Hibernate 5.2.1.Final with SQLite (driver: Xerial 3.11.8.2) and Maven. The problem is, that Hibernate can't find my named queries (which are located in an entity provided with @Entity (javax.persistence.Entity) annotation. I've searched everywhere for a solution so far, but I couldn't make it work.</p>

<p>I've recently switched to Hibernate API instead of using a JPA one - I had no issues before and I haven't made any modifications to this named query. As far as I'm concerned, I can still use javax.persistence annotations.</p>

<p>Exception I'm getting:</p>

<pre><code> Caused by: java.lang.IllegalArgumentException: No query defined for that name [SugerowanaPozycja.getByCategory]
    at org.hibernate.internal.AbstractSharedSessionContract.getNamedQuery(AbstractSharedSessionContract.java:546)
    at org.hibernate.internal.AbstractSharedSessionContract.getNamedQuery(AbstractSharedSessionContract.java:101)
    at pl.nombritech.Menual.dao.SugerowanaPozycjaDAO.getByKategoria(SugerowanaPozycjaDAO.java:90)
    at pl.nombritech.Menual.view.GlowneOknoController.uzupelnijSugerowanePozycje(GlowneOknoController.java:227)
    at pl.nombritech.Menual.view.GlowneOknoController.initialize(GlowneOknoController.java:210)
    ... 22 more
</code></pre>

<p>Annotations in my entity class:</p>

<pre><code>import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

    @Entity
    @NamedQueries({ 
    @NamedQuery(name = "SugerowanaPozycja.getByCategory",
    query = "SELECT e FROM SugerowanaPozycja e WHERE e.kategoria = :kategoria")
    })
</code></pre>

<p>And it is where the exception happens:</p>

<pre><code>public static ObservableList&lt;SugerowanaPozycja&gt; getByKategoria(String kategoria)
{
    Session session = Main.SESSION_FACTORY.openSession();

    Transaction transaction = session.beginTransaction();

    Query&lt;SugerowanaPozycja&gt; query = session.getNamedQuery("SugerowanaPozycja.getByCategory"); // exception here
    query.setParameter("kategoria", kategoria);
    ObservableList&lt;SugerowanaPozycja&gt; list = FXCollections.observableArrayList(query.getResultList());

    transaction.commit();

    session.close();

    return list;
}
</code></pre>

<p>My hibernate.cfg.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;

&lt;hibernate-configuration&gt;
    &lt;session-factory&gt;
        &lt;property name="hibernate.connection.driver_class"&gt;org.sqlite.JDBC&lt;/property&gt;
        &lt;property name="hibernate.connection.url"&gt;jdbc:sqlite:menual_data/bazadb.db&lt;/property&gt;
        &lt;property name="hibernate.connection.username"&gt;&lt;/property&gt;
        &lt;property name="hibernate.connection.password"&gt;&lt;/property&gt;
        &lt;property name="hibernate.dialect"&gt;pl.nombritech.Menual.util.SQLiteDialect&lt;/property&gt;
        &lt;property name="show_sql"&gt;true&lt;/property&gt;
        &lt;property name="format_sql"&gt;true&lt;/property&gt;
        &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;
        &lt;property name="hibernate.c3p0.min_size"&gt;1&lt;/property&gt;
        &lt;property name="hibernate.c3p0.max_size"&gt;1&lt;/property&gt;
    &lt;/session-factory&gt;
&lt;/hibernate-configuration&gt;
</code></pre>

<p>And finally how I initialize Hibernate:</p>

<pre><code>public static SessionFactory SESSION_FACTORY;

Configuration configuration = new Configuration().configure(Main.class.getResource("/hibernate.cfg.xml"));
StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
serviceRegistryBuilder.applySettings(configuration.getProperties());
ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
SESSION_FACTORY = configuration.buildSessionFactory(serviceRegistry);
</code></pre>

<p>I would be very grateful for any hints in this matter. I know there was a lot of such threads here, but it didn't help in my case.</p>