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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:12:03+00:00 2026-06-01T16:12:03+00:00

This is a standalone java application, not web application. So when I persist the

  • 0

This is a standalone java application, not web application. So when I persist the object like this

public <T> T create(T t) {
    em.getTransaction().begin();
    em.persist(t);
    em.flush();
    em.getTransaction().commit();
    return t;
}

The id inside the T t object is still null, even though a new row with correct data and id is created correctly inside the database. Usually in my web app that utilize @EJB, the id available right after I persist, since it persist the entity object into my persistence context, I am not sure if I have my persistence context here?

This is how I mapped my id inside my @Entity Class

@Id
@Basic(optional = false)
@Column(name = "ID")
private Long id;

also I make the id of this table in the database AUTO_INCREMENT, like this

CREATE TABLE Config
(
    ID int NOT NULL AUTO_INCREMENT,
    PRIMARY KEY (ID)
)

This is how I obtain my EntityManager

EntityManagerFactory emf = Persistence.createEntityManagerFactory("CorePU");
em = emf.createEntityManager();

Here is what inside my persistence.xml

<persistence-unit name="CorePU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>    
<class>com.wf.docsys.core.model.Config</class>    
<properties>
  <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/XNINFODB"/>
  <property name="javax.persistence.jdbc.password" value="xxx"/>
  <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
  <property name="javax.persistence.jdbc.user" value="xxx"/>
</properties>

Please help, I am not sure what I did wrong here.

  • 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-01T16:12:04+00:00Added an answer on June 1, 2026 at 4:12 pm

    Here is my answer. Tested

    When mapping your Id, switch from what I have above, which is

    @Id
    @Basic(optional = false)
    @Column(name = "ID")
    private Long id;
    

    to

    @Entity
    public class Person {
       @Id
       @TableGenerator(name="TABLE_GEN", table="SEQUENCE_TABLE", pkColumnName="SEQ_NAME",
           valueColumnName="SEQ_COUNT", pkColumnValue="PERSON_SEQ")
       @GeneratedValue(strategy=GenerationType.TABLE, generator="TABLE_GEN")
       private long id;
       ...
    }
    

    Since I use microsoft SQL server, I have to use @TableGenerator. More information can be found here http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Table_sequencing

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

Sidebar

Related Questions

I have a standalone enum type defined, something like this: package my.pkg.types; public enum
Not sure who is responsible for this error: Exception in thread main java.lang.OutOfMemoryError: PermGen
We have 2 java web apps both are read/write and 3 standalone java read/write
I have some code which is a standalone java application comprising of 30+ classes.
Let's say that you have a standalone application (a Java application in my case)
I have a java web application built on Stuts2/Google Guice/JPA. It uses hibernate as
Hai I am developing a standalone application using Java in which I am using
I want to run a standalone java application on a remote server. It would
I would like to distribute a Java application for Windows. It's Windows-only because it
I have been facing this issue with my application and do not know what

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.