Question

I tried to deploy a JavaEE Web app with JPA persistence on a Glassfish server I installed on an Amazon EC2 instance. Everything worked fine for the deployment and for web pages rendering in my browser, but when I try to use persistence the result is the error "Table/View 'ATHLETE' does not exist'.

This is the first time I try to develop a web app with JPA and I'm trying to create a skeleton to use in the future for we app, but I think I'm missing a fundamental part. Also, using @GeneratedValue for the @Id I get a SEQUENCE table missing error. I'm afraid the two problems are related

The Athlete.java

package com.storassa.javaee.scuolesci;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQuery;


@Entity
@NamedQuery(name = "findAllAthletes", query = "SELECT b FROM Athlete b")
public class Athlete {

        static int idRaw; // I use this to avoid the @GeneratedValue issue

        @Id
        int id;
        String name, surname;
        int birth;

        public Athlete () {
                idRaw++;
                id = idRaw;
        }

       <getters and setters>
}

The AthleteEjb.java

package com.storassa.javaee.scuolesci;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Startup;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.annotation.sql.*;

@LocalBean
@Stateless
public class AthleteEJB {

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

        public List<Athlete> findAthlete() {
                Query query = em.createNamedQuery("findAllAthletes");
                return query.getResultList();
        }

        public Athlete createAthlete(Athlete athlete) {
                em.persist(athlete);
                return athlete;
        }
}

The persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
        version="2.1">
        <persistence-unit name="scuoleSciPU" transaction-type="JTA">
                <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
                <class>com.storassa.javaee.scuolesci.Athlete</class>
                <properties>
                        <property name="eclipselink.target-database" value="DERBY" />
                        <property name="eclipselink.jdbc.driver" 
                                value="org.apache.derby.jdbc.ClientDriver" />
                        <property name="eclipselink.jdbc.url"
                                value="jdbc:derby://localhost:1527;create=true" />
                        <property name="eclipselink.jdbc.user" value="APP" />
                        <property name="eclipselink.jdbc.password" value="APP" />
                        <property name="eclipselink.ddl-generation" value=" drop-and-create-tables" />
                        <property name="eclipselink.logging.level" value="INFO" />
                        <property name="eclipselink.deploy-on-startup" value="true" />
                </properties>
        </persistence-unit>
</persistence>

The error returned on the browser

type Exception report

message Internal Server Error

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: javax.ejb.EJBException: Transaction aborted

root cause

javax.faces.el.EvaluationException: javax.ejb.EJBException: Transaction aborted

root cause

javax.ejb.EJBException: Transaction aborted

root cause

javax.transaction.RollbackException: Transaction marked for rollback.

root cause

javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Table/View 'ATHLETE' does not exist.
Error Code: -20001
Call: INSERT INTO ATHLETE (ID, BIRTH, NAME, SURNAME) VALUES (?, ?, ?, ?)
    bind => [4 parameters bound]
Query: InsertObjectQuery(com.storassa.javaee.scuolesci.Athlete@65fd5648)

root cause

Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Table/View 'ATHLETE' does not exist.
Error Code: -20001
Call: INSERT INTO ATHLETE (ID, BIRTH, NAME, SURNAME) VALUES (?, ?, ?, ?)
    bind => [4 parameters bound]
Query: InsertObjectQuery(com.storassa.javaee.scuolesci.Athlete@65fd5648)

root cause

java.sql.SQLSyntaxErrorException: Table/View 'ATHLETE' does not exist.

root cause

org.apache.derby.client.am.SqlException: Table/View 'ATHLETE' does not exist.

I don't provide web-related resource/classes as I don't think they can be useful. In case let me know.

Should the table ATHLETE be created due to the @Entity annotation and the ?

Was it helpful?

Solution

I guess the problem is related to leading space in eclipselink.ddl-generation value. In other words try to replace:

<property name="eclipselink.ddl-generation" value=" drop-and-create-tables" />

with

<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top