1

I'm trying to run simple JPA example from book Beginning_Java_EE_6_with_GlassFish_3(DerbyDB + eclipselink + maven). The problem is the same as in question The same question

But my persistence configuration presented bellow:

    <?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
             http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
    <persistence-unit name="chapter02PU" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/__default</jta-data-source>
        <class>com.apress.javaee6.chapter02.Book</class>
        <properties>
            <property name="elipselink.target-database" value="DERBY"/>
            <property name="elipselink.ddl-generation" value="drop-and-create-tables"/>
            <property name="elipselink.logging.level" value="ALL"/>
            <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/chapter02DB;create=true"/>
            <property name="javax.persistence.jdbc.user" value="APP"/>
            <property name="javax.persistence.jdbc.password" value="APP"/>
        </properties>
    </persistence-unit>
</persistence>

here is the main class:

package com.apress.javaee6.chapter02;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

public class Main {

    public static void main(String[] args) {
        Book book = new Book.BookBuilder()
                .title("The Chitchiker's description to Galaxy")
                .price(12.5F)
                .description("Since fiction comedy book")
                .isbn("1-84023-666")
                .numOfPage(354)
                .illustration(false)
                .build();

        EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("chapter02PU");
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        EntityTransaction transaction = entityManager.getTransaction();

        transaction.begin();
        entityManager.persist(book);
        transaction.commit();

        entityManager.close();
        entityManagerFactory.close();
    }
}

And the Book.class

@Entity
@NamedQuery(name = "findAllBooks", query = "select b from Book b")
public class Book {

    public Book() {
    }

    @Id @GeneratedValue
    private Long id;

    @Column(nullable = false)
    private String title;

    private Float price;

    @Column(length = 2000)
    private String description;

    private String isbn;

    private Integer numOfPage;

    private Boolean illustration;

So I also looked up several questions(how to setup JTA datasource) about Glassfish and JDBC Resource, but they are presented in GlassFish console(jdbc/__default).

So finally when I run my program with command

mvn exec:java -Dexec.mainClass="com.apress.javaee6.chapter02.Main"

My pom.xml is

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.apress.javaee6</groupId>
    <artifactId>chapter02</artifactId>
    <version>1.0</version>
    <name>chapter02</name>

    <dependencies>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>javax.persistence</artifactId>
            <version>2.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>eclipselink</artifactId>
            <version>2.5.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derbyclient</artifactId>
            <version>10.10.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derby</artifactId>
            <version>10.10.2.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <inherited>true</inherited>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

I get an error

[ERROR] Internal Exception: java.sql.SQLSyntaxErrorException: Table/View 'SEQUEN
CE' does not exist.
[ERROR] Error Code: 20000
[ERROR] Call: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
[ERROR] bind => [2 parameters bound]
[ERROR] Query: DataModifyQuery(name="SEQUENCE" sql="UPDATE SEQUENCE SET SEQ_COUN
T = SEQ_COUNT + ? WHERE SEQ_NAME = ?")
[ERROR] -> [Help 1]
[ERROR]

I search for related questions but I can't recognize where my mistake is. Can someone help me? UPD1 I enabled logs in derbyDB:

Database Class Loader started - derby.database.classpath=''
Sun Jan 18 23:56:39 MSK 2015 Thread[DRDAConnThread_2,5,main] (XID = 166), (SESSIONID = 0), (DATABASE = chapter02DB), (DRDAID = {1}), Committing
Sun Jan 18 23:56:39 MSK 2015 Thread[DRDAConnThread_2,5,main] (XID = 166), (SESSIONID = 0), (DATABASE = chapter02DB), (DRDAID = {1}), Rolling back
Sun Jan 18 23:56:39 MSK 2015 Thread[DRDAConnThread_2,5,main] (XID = 167), (SESSIONID = 1), (DATABASE = chapter02DB), (DRDAID = {1}), Committing
Sun Jan 18 23:56:39 MSK 2015 Thread[DRDAConnThread_2,5,main] (XID = 167), (SESSIONID = 1), (DATABASE = chapter02DB), (DRDAID = {1}), Committing
Sun Jan 18 23:56:39 MSK 2015 Thread[DRDAConnThread_2,5,main] (XID = 167), (SESSIONID = 1), (DATABASE = chapter02DB), (DRDAID = ????????.????-4255337276300706295{1}), Committing
Sun Jan 18 23:56:39 MSK 2015 Thread[DRDAConnThread_2,5,main] (XID = 167), (SESSIONID = 1), (DATABASE = chapter02DB), (DRDAID = ????????.????-4255337276300706295{1}), Rolling back
Sun Jan 18 23:56:39 MSK 2015 Thread[DRDAConnThread_2,5,main] (XID = 167), (SESSIONID = 1), (DATABASE = chapter02DB), (DRDAID = ????????.????-4255337276300706295{1}), Rolling back
Sun Jan 18 23:56:39 MSK 2015 Thread[DRDAConnThread_2,5,main] (XID = 168), (SESSIONID = 2), (DATABASE = chapter02DB), (DRDAID = {2}), Committing
Sun Jan 18 23:56:39 MSK 2015 Thread[DRDAConnThread_2,5,main] (XID = 168), (SESSIONID = 2), (DATABASE = chapter02DB), (DRDAID = {2}), Rolling back
Sun Jan 18 23:56:39 MSK 2015 Thread[DRDAConnThread_2,5,main] (XID = 169), (SESSIONID = 3), (DATABASE = chapter02DB), (DRDAID = {2}), Committing
Sun Jan 18 23:56:39 MSK 2015 Thread[DRDAConnThread_2,5,main] (XID = 169), (SESSIONID = 3), (DATABASE = chapter02DB), (DRDAID = {2}), Committing
Sun Jan 18 23:56:39 MSK 2015 Thread[DRDAConnThread_2,5,main] (XID = 170), (SESSIONID = 3), (DATABASE = chapter02DB), (DRDAID = ????????.????-4254774326347276936{2}), Begin compiling prepared statement: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ? :End prepared statement
Sun Jan 18 23:56:39 MSK 2015 Thread[DRDAConnThread_2,5,main] (XID = 170), (SESSIONID = 3), (DATABASE = chapter02DB), (DRDAID = ????????.????-4254774326347276936{2}), Error compiling prepared statement: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ? :End prepared statement
Community
  • 1
  • 1
user2105282
  • 724
  • 1
  • 12
  • 26
  • Where can I find some logs to resolve this problem? – user2105282 Jan 18 '15 at 15:58
  • When you startup your Derby Network Server (the process which is listening on port 1527), pass -Dderby.language.logStatementText=true, then look in the derby.log that your Derby Network Server writes to see all the SQL statements that your program is issuing to the database. You'll need to create the table SEQUENCE before you can update it, of course, so the thing you need to track down here is why the CREATE TABLE is not being run. – Bryan Pendleton Jan 18 '15 at 18:49
  • From logs I can see that at first step it tries to update SEQUENCE table. Should I create this table manually? – user2105282 Jan 18 '15 at 20:02
  • 1
    God damn! I found the error))) It was 'elipselink' instead of 'eclipselink'. Spent a couple of ours due to this fool mistake – user2105282 Jan 18 '15 at 20:09
  • You should post your solution as an answer to show that the problem was solved :) – unwichtich Jan 18 '15 at 22:43

1 Answers1

0

it was the mistake in persistance.xml

Instead of

<properties>
    <property name="elipselink.target-database" value="DERBY"/>
    <property name="elipselink.ddl-generation" value="drop-and-create-tables"/>
    <property name="elipselink.logging.level" value="ALL"/>

Should be

<properties>
    <property name="eclipselink.target-database" value="DERBY"/>
    <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
    <property name="eclipselink.logging.level" value="ALL"/>

Enable transactional logs in derby DB really helps me (Dderby.language.logStatementText=true). From this logs I saw that no tables are created on start up

user2105282
  • 724
  • 1
  • 12
  • 26