Пытаюсь сделать простой запрос через jpa. Вылетает эта дрянь. Что это может быть?
java.lang.IllegalArgumentException: No query defined for that name {User.getAll}
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.buildQueryFromName(AbstractEntityManagerImpl.java:788)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createNamedQuery(AbstractEntityManagerImpl.java:925)
at ru.example.dao.user.UserDao.loadUser(UserDao.java:39)
...
User.java:
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
@XmlRootElement
@Entity
@Table(name = "users")
@NamedQueries({
@NamedQuery(name = "User.getAll", query = "SELECT u from User u"),
@NamedQuery(name = "User.getByLogin", query = "SELECT u FROM User u WHERE u.login = :login")
})
public class User implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(name = "login", length = 50)
private String login;
public long getId() { return id; }
public void setId(long id) { this.id = id; }
public String getLogin() { return login; }
public void setLogin(String login) { this.login = login;}
}
UserDao.java:
import ru.example.db.user.User;
import javax.persistence.TypedQuery;
public class UserDao {
public User loadUser() {
EntityManager em = Persistence.createEntityManagerFactory("JPA").createEntityManager();
TypedQuery <User> namedQuery = em.createNamedQuery("User.getAll", User.class);
return namedQuery.getResultList().get(0);
}
}
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="JPA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.archive.autodetection" value="true"/>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/postgres"/>
<property name="hibernate.connection.schema" value="public"/>
<property name="hibernate.connection.username" value="postgres"/>
<property name="hibernate.connection.password" value="owner"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL9Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>