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 8756237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:01:44+00:00 2026-06-13T14:01:44+00:00

I am trying to insert a record in the database (using Java EE 6,

  • 0

I am trying to insert a record in the database (using Java EE 6, EJB 3.1, JPA 2.0). I am getting an error that accountTypeId field is null, but i have set it up as autogenerate. Can anyone please suggest what am I doing wrong?

Following is the create table query:

create table example.account_type(
    account_type_id INT NOT null PRIMARY KEY GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
    account_type_desc varchar(20)
);

Following is the entity class:

EDIT: Updated the entity class as generated by NetBeans which didn’t work. I also added @GeneratedValue annotation but still it didn’t work.

@Entity
@Table(name = "ACCOUNT_TYPE")
@NamedQueries({
    @NamedQuery(name = "AccountType.findAll", query = "SELECT a FROM AccountType a"),
    @NamedQuery(name = "AccountType.findByAccountTypeId", query = "SELECT a FROM AccountType a WHERE a.accountTypeId = :accountTypeId"),
    @NamedQuery(name = "AccountType.findByAccountTypeDesc", query = "SELECT a FROM AccountType a WHERE a.accountTypeDesc = :accountTypeDesc")})
public class AccountType implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)  // ADDED THIS LINE
    @Basic(optional = false)
    @NotNull
    @Column(name = "ACCOUNT_TYPE_ID")
    private Integer accountTypeId;
    @Size(max = 50)
    @Column(name = "ACCOUNT_TYPE_DESC")
    private String accountTypeDesc;

    public AccountType() {
    }

    public AccountType(Integer accountTypeId) {
        this.accountTypeId = accountTypeId;
    }

    public Integer getAccountTypeId() {
        return accountTypeId;
    }

    public void setAccountTypeId(Integer accountTypeId) {
        this.accountTypeId = accountTypeId;
    }

    public String getAccountTypeDesc() {
        return accountTypeDesc;
    }

    public void setAccountTypeDesc(String accountTypeDesc) {
        this.accountTypeDesc = accountTypeDesc;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (accountTypeId != null ? accountTypeId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof AccountType)) {
            return false;
        }
        AccountType other = (AccountType) object;
        if ((this.accountTypeId == null && other.accountTypeId != null) || (this.accountTypeId != null && !this.accountTypeId.equals(other.accountTypeId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entities.AccountType[ accountTypeId=" + accountTypeId + " ]";
    }

}

Following is the session bean interface:

@Remote
public interface AccountTypeSessionBeanRemote {
    public void createAccountType();
    public void createAccountType(String accDesc);
}

Following is the session bean implementation class:

@Stateless
public class AccountTypeSessionBean implements AccountTypeSessionBeanRemote {
    @PersistenceContext(unitName="ExamplePU")
    private EntityManager em;

    @Override
    public void createAccountType(String accDesc) {
        AccountType emp = new AccountType(accDsc);
       try {
           this.em.persist(emp);
           System.out.println("after persist");
       } catch(Exception ex) {
           System.out.println("ex: " + ex.getMessage());
       }
    }
}

Following is the Main class:

public class Main {
    @EJB
    private static AccountTypeSessionBeanRemote accountTypeSessionBean;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        accountTypeSessionBean.createAccountType("test");
    }
}

Following is the error:

INFO: ex: Object: Entities.AccountType[ accountTypeId=null ] is not a known entity type.
  • 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-06-13T14:01:47+00:00Added an answer on June 13, 2026 at 2:01 pm

    I changed my create table query as following:

    create table example.account_type(
        account_type_id INT NOT null PRIMARY KEY,
        account_type_desc varchar(20)
    );
    

    Then had to add the following line to the entity class (Netbeans doesn’t add that):

    @GeneratedValue(strategy = GenerationType.AUTO)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to insert a record into the database but it is giving me
I am trying to insert a record into a table using Linq but get
I'm trying to insert records in mysql database using java, What do I place
I have trying to insert a record into the database (MySQL), using Entity Class
I'm using a mysql database, and I'm trying to insert a record into tableB
I am trying to insert a record into the database i am using Spring
I am getting syntax error when trying to insert data into my database when
I am trying to insert a record into my database. here is my php
I'm trying to insert a record (on LINQ to SQL) to the database. So
I'am trying to insert record into db2 table and getting a result with response.write.

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.