Question

I have a problem with my web application: in the manage bean I have:

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

and when this method starts, i have this exception (from userFacade probably):

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 and UserFacade are auto generate in Netbeans ("Entity Class from database..." and "Session Beans From Entity Class...":

Could you help me to understend what mean "user lacks privilege" ?

Edit:

Problem is here:

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

when query is created the exception is thrown

Was it helpful?

Solution 2

Problem isn't with database, i have to change my JPA configuration:

To get EntityManager from

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

i have to change my persistance.xml, change transaction-type to "JTA" and add:

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

after that, i have to declare resources in my server configuration: at [tomee installation folder]/conf/tomee.xml file:

<?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>

Look there:

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/

OTHER TIPS

The user you use to execute the statement does not have adequate privileges to create a table.

As @duffymo mentiones in the comments, the youser need to be granted appropriate privileges. In my experience it is not a good idea to give the application's (technical) user these privileges.

Create the DB schema with a database admin that is not used as technical application user.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top