0

I have a JAR which contains only my model which are annotated classes. Then the application which loads the JAR.

In the persistence.xml of the app I have:

<jar-file> my jar </jar-file>

and in the properties:

<property name="hibernate.archive.autodetection" value="class" />

That works. The entities are detected and this query works fine:

List<Event> events = em.createQuery(
"from com.my.namespace.model.Event", Event.class).getResultList();

However I absolutely need to have the namespace in the query... If I do:

List<Event> events = em.createQuery("from Event", Event.class).getResultList();

Then I get this exception:

Event is not mapped [from Event]

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.

How do I get the JPAQL/HQL to "import" the right package to see that entity without needing to explicitely type the namespace?

Update: here is Event.java if it helps.. it is as trivial as it gets:

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;
    }
}
1
  • can you post Event.java, how you mapped Table and Entity ? Commented Jan 4, 2013 at 9:09

2 Answers 2

2

@Entity(name="events") is the culprit

it has to be

          @Entity
          @Table(name="events")

If you intenteded events as db table name. Otherwise use events in your query instead of Event

Sign up to request clarification or add additional context in comments.

1 Comment

thank you for telling me what I intended to type, separating the @Table annotation. A bit shocked because that worked fine with hibernate-core.
2

Since your name of the entity is "events" (from @Entity(name="events")) you should select from "events" not "event".

List<Event> events = em.createQuery("from events", Event.class).getResultList();

should therefore work

3 Comments

no, what you should type in HQL/JPAQL is the class name, besides as I wrote it works with the namespace. I tried your suggestion anyway and it doesn't work, with and without the namespace.
is it from Events or from events ?
I understand now, you are right. This mapping worked as-is with hibernate-core! I thought there is no difference between hibernate-core annotationsand JPA annotations...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.