Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6986911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:52:09+00:00 2026-05-27T18:52:09+00:00

I want to use SEQUENCE strategy for automatically generate ids, but i am breaking

  • 0

I want to use SEQUENCE strategy for automatically generate ids, but i am breaking my head to make it work. I dont know at all why i cant make it happen.

This is what i do.
First i have an entity:

 @Entity
@SequenceGenerator(name="VlasnikSeq", sequenceName="VLA_SEQ")
public class Vlasnik implements Serializable {

    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="VlasnikSeq")
    private Long id;
    //...

in the persistence.xml i have it mapped:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
    <persistence-unit name="sampleAplication">
    <class>entities.Vlasnik</class>
    <class>entities.Ljubimac</class>
    </persistence-unit>
</persistence>

When i use eclipses feature for generating tables for entities i get this:

enter image description here

As you can see the tables are created, but there is no SEQUENCE table.
I also noticed in the console, the following message, while JPA was creating the tables:

[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence
Services – 2.3.0.v20110604-r9504):
org.eclipse.persistence.exceptions.DatabaseException Internal
Exception: java.sql.SQLSyntaxErrorException: SEQUENCE ‘VLA_SEQ’ does
not exist.

The next think i do is try to run the app and see if i can create some rows. But when i try to persist something, i get an exception that says:

org.apache.derby.client.am.SqlException: SEQUENCE ‘VLA_SEQ’ does not

So i come to the conclusion that for some reason i need that table, so i go to the database management perspective and i try to execute the following query:

CREATE SEQUENCE VLA_SEQ;

But i get the following message:

Sequence ‘VLA_SEQ’ already exists.

I am totally confused. I don’t know what should i do. I just want to automatically generate the IDs of my entities when a new row is created in the DB.

It is the first time i use glassfish 3.1, in the version 3.0 i dont remember, having this issue, i could even use just @GenneratedValue.
Ill appreciate some help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:52:09+00:00Added an answer on May 27, 2026 at 6:52 pm

    In order to use GeneratedValue you have to specify the strategy and the generator. By default the strategy is AUTO and the generator is empty.

    The avaliable strategies are defined by GenerationType:

    public enum GenerationType { TABLE, SEQUENCE, IDENTITY, AUTO };
    

    The most common way to use it is by specifying SEQUENCE or IDENTITY.

    • For databases that use SEQUENCE such as Oracle and HSQLDB you also have to use SequenceGenerator annotation:

      public class MyClass {

      @Id
      @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQMYCLASSID")
      @SequenceGenerator(name="SEQMYCLASSID", sequenceName="SEQMYCLASSID")
      private Long id;
      

      }

    If you have automatic DDL enable you don’t have to create the sequence because the JPA provider will do it for you. If that’s not the case you have to do it manually like this:

    CREATE SEQUENCE SEQMYCLASSID;
    
    • For databases that don’t use squences and use identity columns such as Microsoft SQL Server you need to specify IDENTITY as strategy:

      public class MyClass {

      @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)  
      private Long id;
      

      }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use a custom sequence generator in my application, but the entity
I want to use mixed @Inheritance strategy, but Hibernate doesn't support it. Is there
I know this may seem quite basic to geeks. But I want to make
I have a sequence of SQL calls, which I want to use to detect
Below is my stored procedure. I want use stored procedure select all row of
I want to select all the rows in my database but I want them
I want to use RollingMode.Date to log by date. But default interval is one
I want to use the Split function on a string but keep the delimiting
I want to use LINQ to call stored procedure in this way but stored
I want to use base36 in a web application I am developing... but as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.