Note that there are some explanatory texts on larger screens.

plurals
  1. POhibernate JPA query works only with namespace
    primarykey
    data
    text
    <p>I have a JAR which contains only my model which are annotated classes. Then the application which loads the JAR.</p> <p>In the persistence.xml of the app I have:</p> <p><code>&lt;jar-file&gt; my jar &lt;/jar-file&gt;</code></p> <p>and in the properties:</p> <p><code>&lt;property name="hibernate.archive.autodetection" value="class" /&gt;</code></p> <p>That works. The entities are detected and this query works fine:</p> <pre><code>List&lt;Event&gt; events = em.createQuery( "from com.my.namespace.model.Event", Event.class).getResultList(); </code></pre> <p>However I absolutely need to have the namespace in the query... If I do:</p> <pre><code>List&lt;Event&gt; events = em.createQuery("from Event", Event.class).getResultList(); </code></pre> <p>Then I get this exception:</p> <pre><code>Event is not mapped [from Event] </code></pre> <p>What is even more frustrating is that I give to JPA the class, Event.class as the second argument of my call. The Java codes imports the right package.</p> <p>How do I get the JPAQL/HQL to "import" the right package to see that entity without needing to explicitely type the namespace?</p> <p><strong>Update:</strong> here is Event.java if it helps.. it is as trivial as it gets:</p> <pre><code>package com.my.namespace.model; import javax.persistence.*; @Entity(name="events") @SequenceGenerator(name="events_id_seq", sequenceName="events_id_seq") public class Event { @Id @Column(name="id") @GeneratedValue(generator="events_id_seq") private Long mId; @Column(name="title") private String mTitle; public Long getId() { return mId; } public String getTitle() { return mTitle; } public void setTitle(String title) { mTitle = title; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload