为什么我不能使用JPA,数据库和引号在一起? [英] Why can't I use JPA, database and primefaces together?

查看:156
本文介绍了为什么我不能使用JPA,数据库和引号在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个User类,whitch是一个数据库 @Entity for JPA。

I have a User class, whitch is a database @Entity for JPA.

我有一个UserServiceImpl类,它们有 getAllUser()方法(从下面的异常:UserServiceImpl.java:16=第二行):

I have a UserServiceImpl class, which have this getAllUser() method (from the Exception below: UserServiceImpl.java:16=the second row):

public UserServiceImpl(){
    em = EMService.getEntityManager();
}
@Override
@SuppressWarnings("unchecked")
public List<User> getAllUser() {
    String jpql = "SELECT u FROM User u";
    Query q = em.createQuery(jpql);
    List<User> users = (List<User>) q.getSingleResult();
    return users;
}

我有一个UserBean类, c> faces-config.xml 。而且会有Exception(UserBean.java:19=第5行):

I have a UserBean class, whitch is managed bean in the faces-config.xml for the primefaces. And there will be the Exception (UserBean.java:19=5th row):

private List<User> users;
private User selectedUser;
private UserServiceImpl userService;
public UserBean() {
    userService = new UserServiceImpl();
    users = userService.getAllUser();
}
public List<User> getUsers() {
    return users;
}



我想,问题是托管bean不能使用另一个类。这是例外:

I think, the problem is that a managed bean can't use another classes. This is the Exception:

java.lang.NoClassDefFoundError: javax/persistence/Persistence
at hu.pte.admin.services.EMService.getEntityManager(EMService.java:12)
at hu.pte.admin.services.usersmodul.UserServiceImpl.<init>(UserServiceImpl.java:16)
at hu.pte.admin.managedbeans.UserBean.<init>(UserBean.java:19)

的EMService类(第二行是错误的= EMService.java:12):

This is the method of the EMService class (the second row is the wrong = EMService.java:12):

public static EntityManager getEntityManager(){
    EntityManagerFactory factory = Persistence.createEntityManagerFactory("Admin");
    EntityManager em = factory.createEntityManager();
    return em;
}

这是users.xhtml管理bean(userBean)中的原始代码:

And this is the users.xhtml (detail), where i want to use the managed bean (userBean) in the primefaces code:

<p:dataTable var="user" value="#{userBean.users}" paginator="true" rows="10"
        selection="#{userBean.selectedUser}" selectionMode="single" 
        onRowSelectUpdate="display" rowsPerPageTemplate="5,10,15">
        <f:facet name="header">The Users</f:facet>

        <p:column sortBy="#{user.id}" filterBy="#{user.id}">
            <f:facet name="header">
                <h:outputText value="ID" />
            </f:facet>
            <h:outputText value="#{user.id}" />
        </p:column>

persistance.xml具有连接到我的数据库的代码。请帮助我,我找不到任何样品在互联网,whitch使用JPA和PrimeFaces在一起这样!

The persistance.xml has the code to connect to my database. Please help me, i can't find any sample in the internet, whitch are use JPA and PrimeFaces together like this! Thanks!!

推荐答案

例外清楚地显示了您:

java.lang.NoClassDefFoundError: javax/persistence/Persistence

没有找到 javax.persistence.Persistence 类的类定义。我假设你正在运行一个Java SE SDK。我建议您下载并运行 Java EE 6 SDK ,其中包含持久性 API。

There is no class definition found for javax.persistence.Persistence class. I'm assuming you're running a Java SE SDK. I suggest downloading and running the Java EE 6 SDK which inlcudes the Persistence API.

这篇关于为什么我不能使用JPA,数据库和引号在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆