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

  • Home
  • SEARCH
  • 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 6047485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:21:22+00:00 2026-05-23T07:21:22+00:00

I am a Java EE/JPA newbie, currently attending a beginners course on Java EE

  • 0

I am a Java EE/JPA newbie, currently attending a beginners course on Java EE programming.

I am trying to create new entries in a database which has a sequence defined for
generating an ID, which is to be used as the primary key.

This is the Entity, which was generated by Eclipse from the database table:

@Entity
@Table(name = "ADDR_PROJ")
public class AddrProj implements Serializable
{
   private static final long serialVersionUID = 1L;

   @Id
   @SequenceGenerator(name = "ADDR_PROJ_ID_GENERATOR", sequenceName = "ADDR_SEQ")
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
"ADDR_PROJ_ID_GENERATOR")
   @Column(insertable = false, updatable = false)
   private long id;

   // ...
   // other fields
}

(BTW, long getId() is implemented, but void setId(long) is not.)

The table and sequence were created using the following SQL statements:

CREATE TABLE addr_proj (
    id           INTEGER PRIMARY KEY,
    name         VARCHAR(30),
    address      VARCHAR(30),
    birthday     DATE,
    email        VARCHAR(50),
    workphone    DECIMAL(4,0)
);

CREATE SEQUENCE addr_seq
START WITH 1
INCREMENT BY 1
NOMAXVALUE;

Manual insertions into the table work fine using statements like this:

INSERT INTO addr_proj VALUES
(
   addr_seq.nextval,
   'Matt',
   '3 Fake Ave, Madeuptown',
   '01-apr-1980',
   'matt@madeupemail.com',
   '1234'
);

However, when I try to update via the DAO, I get errors like the following:

Caused By: org.apache.openjpa.lib.jdbc.ReportingSQLException:
ORA-01400: cannot insert NULL into ("AJP05"."ADDR_PROJ"."ID")
{prepstmnt 28 INSERT INTO ADDR_PROJ (address, birthday, email, name,
workphone) VALUES (?, ?, ?, ?, ?) [params=(String) 43 Fake Ln, NotA
City, (Date) 1963-02-04, (String) pete@email.not, (String) Pete,
(BigDecimal) 1337]} [code=1400, state=23000]
   at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:192)
   at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$700(LoggingConnectionDecorator.java:57)
   at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:866)
   at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:269)
   at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeUpdate(JDBCStoreManager.java:1421)
   Truncated. see log file for complete stacktrace

Note that the code is trying to insert 5 values, when 6 are required – the ID is missing.

The DAO code looks (something) like this:

void add(AddrProj item) {
    em.persist(item);
}

What’s causing this problem?

Do I need a setId(long) method in my Entity class?

Do I need special code in the DAO’s add() method to manage the
sequence generator?

Am I missing something else?

Note: This is homework, but my choice to try using an auto-generated primary key was a bit beyond the scope of the assignment. It hasn’t been covered in the course.

  • 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-23T07:21:23+00:00Added an answer on May 23, 2026 at 7:21 am

    Remove @Column(insertable = false, updatable = false) and the column will be part of the insert and update.

    Check the jpa hibernate annotation documentation section “2.2.2.3. Declaring column attributes”.

    http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/

    insertable (optional): whether or not the column will be part of the insert statement (default true)
    updatable (optional): whether or not the column will be part of the update statement (default true)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am newbie with JPA. I'm trying to run some sample code using JPA
The JPA (Java Persistence API) specification has 2 different ways to specify entity composite
I have a database in which all of the tables have been generated by
I need to create project in which there are two databases local and remote.
I want to create a project in which it is required to synchronize local
There seems to only be 2nd class support for composite database keys in Java's
Let's say, I have decided to go with Java EE stack for my enterprise
I'm researching the development of Enterprise Applications in Java, .NET and Groovy. For each
This is the same question as: How to dynamically generate SQL query based on
We use Tomcat to host our WAR based applications. We are servlet container compliant

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.