JPAException происходит при попытке доступа к любой странице после безопасного входа - PullRequest
3 голосов
/ 06 июня 2011

На моем сайте с помощью Play !, у меня есть часть администратора.Все административные контроллеры имеют аннотации @With и @Check.

При отключении все идет хорошо.При подключении каждый раз, когда я загружаю страницу (любую страницу, администратор или нет), поднимается JPAException.


Вот проверка администратора:

public class Security extends Secure.Security {

    static boolean authentify(String username, String password) {
        return User.connect(username, password) != null;
    }

    static boolean check(String profile) {
        User user = User.find("byLogin", connected()).<User>first(); /**line 12**/
        renderArgs.put("user", user.login);
        if ("admin".equals(profile)) {
            return user.role == Role.Admin;
        } else if ("manager".equals(profile)) {
            return user.role == Role.Manager || user.role == Role.Admin;
        } else if ("user".equals(profile)) {
            return true;
        }
        return false;
    }
}

Вот исключение:

JPA error
A JPA error occurred (The JPA context is not initialized. JPA Entity Manager automatically start when one or more classes annotated with the @javax.persistence.Entity annotation are found in the application.): 

play.exceptions.JPAException: The JPA context is not initialized. JPA Entity Manager automatically start when one or more classes annotated with the @javax.persistence.Entity annotation are found in the application.
at play.db.jpa.JPA.get(JPA.java:22)
at play.db.jpa.JPA.em(JPA.java:51)
at play.db.jpa.JPQL.em(JPQL.java:16)
at play.db.jpa.JPQL.find(JPQL.java:44)
at models.User.find(User.java)
at controllers.Security.check(Security.java:12)
at play.utils.Java.invokeStaticOrParent(Java.java:159)
at controllers.Secure$Security.invoke(Secure.java:193)
at {play}/framework/templates/tags/404.html.(line:1)
at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:213)
at play.templates.GroovyTemplate$ExecutableTemplate.invokeTag(GroovyTemplate.java:347)
at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:213)
at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:247)
at play.templates.Template.render(Template.java:26)
at play.server.PlayHandler.serve404(PlayHandler.java:634)
at Invocation.HTTP Request(Play!)

Это на самом деле не беспокоитприложение (оно прекрасно работает), но я действительно не знаю, почему это происходит ...

Заранее спасибо!


РЕДАКТИРОВАТЬ:

Пользователькод класса:

@Entity
public class User extends Model {

    @Email
    public String email;

    @Required @Password
    public String password;

    public String fullname;

    @Required @Column(unique=true)
    public String login;

    @Enumerated(EnumType.STRING)
    public Role role=Role.User;

    public static User connect(String login, String password) {
        return find("byLoginAndPassword", login, password).first();
    }

    @Override
    public String toString() {
        return login;
    }
}

1 Ответ

0 голосов
/ 22 июня 2011

Вы раскомментировали следующий код в application.conf ?

db=mem

Воспроизведение запускает контекст JPA, только если база данных активирована в application.conf.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...