2

我的 Web 应用程序有问题:在管理 bean 中我有:

 private boolean isUserInDB() {
    List users = userFacade.findByLogin(registerLog);
    if(users.isEmpty())
        return false;
    return true;
}    

当这个方法开始时,我有这个异常(可能来自 userFacade):

javax.el.ELException: javax.ejb.EJBException:The bean encountered a non-application exception; 
nested exception is: <openjpa-2.2.0-r422266:1244990 fatal general error> org.apache.openjpa.persistence.PersistenceException:
user lacks privilege or object not found: USER {SELECT t0.id_user, t0.login, t0.password FROM USER t0 WHERE (t0.login = ?)} [code=-5501, state=42501] 
FailedObject: SELECT u FROM User u WHERE u.login = :login [java.lang.String]

viewId=/pages/register.xhtml
location=/home/jakub/Projekty/Collv2/build/web/pages/register.xhtml
phaseId=INVOKE_APPLICATION(5)



Caused by:
org.apache.openjpa.lib.jdbc.ReportingSQLException - user lacks privilege or object not found: USER {SELECT t0.id_user, t0.login, t0.password FROM USER t0 WHERE (t0.login = ?)} [code=-5501, state=42501]
at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:247)


or


Caused by:
org.apache.openjpa.lib.jdbc.ReportingSQLException - type not found or user lacks       
privilege: TEXT {stmnt 1932110061 CREATE TABLE COURSE (id_course SMALLINT NOT NULL,
code VARCHAR(255), description TEXT, name VARCHAR(255), realization INTEGER, version 
SMALLINT, PRIMARY KEY (id_course)) ENGINE = innodb} [code=-5509, state=42509]



/pages/register.xhtml at line 26 and column 104 action="#{registerController.register}"

User.class 和 UserFacade 在 Netbeans 中自动生成(“来自数据库的实体类......”和“来自实体类的会话 Bean......”:

你能帮我理解什么是“用户缺乏特权”吗?

编辑:

问题在这里:

public List<User> findByLogin(String login){
    Query q = em.createNamedQuery("User.findByLogin").setParameter("login", login);
    List list = q.getResultList();
    return list;
}

创建查询时抛出异常

4

2 回答 2

3

您用来执行语句的用户没有足够的权限来创建表。

正如@duffymo 在评论中提到的那样,你需要被授予适当的权限。根据我的经验,给应用程序的(技术)用户这些权限并不是一个好主意。

使用不用作技术应用程序用户的数据库管理员创建数据库模式。

于 2013-09-16T13:42:25.470 回答
0

问题不在于数据库,我必须更改我的 JPA 配置:

从 EntityManager 获取

@PersistenceContext(unitName = "CollDocPU")
private EntityManager em;

我必须更改我的persistance.xml,将事务类型更改为“JTA”并添加:

<jta-data-source>java:openejb/Resource/myDatabase</jta-data-source>
<non-jta-data-source>java:openejb/Resource/myDatabaseUnmanaged</non-jta-data-source>

之后,我必须在我的服务器配置中声明资源:在 [tomee 安装文件夹]/conf/tomee.xml 文件中:

<?xml version="1.0" encoding="UTF-8"?>
 <tomee>
  <Resource id="myDatabase" type="DataSource">
   JdbcDriver com.mysql.jdbc.Driver
   JdbcUrl jdbc:mysql://localhost:11080/jkitaj?zeroDateTimeBehavior=convertToNull
   UserName jkitaj
   Password pass,
 </Resource>

 <Resource id="myDatabaseUnmanaged" type="DataSource">
   JdbcDriver com.mysql.jdbc.Driver
   JdbcUrl jdbc:mysql://localhost:11080/jkitaj?zeroDateTimeBehavior=convertToNull
   UserName jkitaj
   Password pass,
   JtaManaged false
 </Resource>
</tomee>

看这里:

http://openejb.979440.n4.nabble.com/org-apache-openjpa-lib-jdbc-ReportingSQLException-type-not-found-or-user-lacks-privilege-td4665124.html

http://mobiarch.wordpress.com/2012/12/07/configuring-a-mysql-data-source-in-tomee/

于 2013-09-23T10:13:58.600 回答