aspose file tools*
The moose likes Object Relational Mapping and the fly likes JPA EclipseLink SEQUENCE table does not exist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA EclipseLink SEQUENCE table does not exist" Watch "JPA EclipseLink SEQUENCE table does not exist" New topic
Author

JPA EclipseLink SEQUENCE table does not exist

Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

Hi,

I want to save Customer entity in database (Derby):


I get reference to EntityManager and then I invoke:
manager.persist(new Customer());

However I get error:

Internal Exception: java.sql.SQLSyntaxErrorException: Table/view 'SEQUENCE' does not exist.
Call: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
bind => [2 parameters bound]


However SEQUENCE table is in my database. It was created automatically when I created tables from entities:
[EL Fine]: Connection(32280137)--CREATE TABLE CUSTOMER (ID BIGINT NOT NULL, NAME VARCHAR(255), PRIMARY KEY (ID))
[EL Fine]: Connection(32280137)--CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT DECIMAL(15), PRIMARY KEY (SEQ_NAME))
[EL Fine]: Connection(32280137)--DELETE FROM SEQUENCE WHERE SEQ_NAME = SEQ_GEN
[EL Fine]: Connection(32280137)--SELECT * FROM SEQUENCE WHERE SEQ_NAME = SEQ_GEN
[EL Fine]: Connection(32280137)--INSERT INTO SEQUENCE(SEQ_NAME, SEQ_COUNT) values (SEQ_GEN, 0)


I do not have any idea. I want to cry (((.

SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3837

Have you ran the schema generation once before running the actual code (link)?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

The problem actually was with that I searched wrong database. I did not specify: <jta-data-source>...</jta-data-source> element in persistence.xml and default database was chosen.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Lucas

When you say the default database, what do you mean?
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

I mean that 'sun-appserv-samples' was chosen. I use Eclipse with Glassfish and Derby. That database was created automatically.

Can someone give me a clue why:

@GeneratedValue(strategy=GenerationType.AUTO)

works flawlessly whereas:

@GeneratedValue(strategy=GenerationType.SEQUENCE)

does not work. It gives exception that ID cannot have NULL value.

James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Using GenerationType.SEQUENCE means you wish the ID to be generated from a sequence which is held as a database object. I'm assuming you ate getting null because you haven't specified which sequence to use.
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

OK, I have solved the problem.

After changing GenerationType in the entity it is necessary to regenerate tables. I use JPA Tools -> Generate tables from entities... from the context menu of JPA Project.

Can someone tell me what is the purpose of <property name="eclipselink.ddl-generation" value="none"/> element in persistence.xml?

By the way:
* adding <property name="eclipselink.logging.level" value="FINE"/> to persistence.xml is very useful while resolving strange issues like "JPA EclipseLink SEQUENCE table does not exist".
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

I think that eclipselink.ddl-generation is similar to Hibernate's hbm2ddl.auto property. It basically allows you to configure how eclipselink manages your database schema.

For example, if you wanted eclipselink to create the database schema, you would use:

Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

OK, but when such creation occurs? During deployment?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPA EclipseLink SEQUENCE table does not exist