I have a local server provided by GlassFish and I have 2 clients: one is generated by server: JSF; and the other one is not on the server: Terminal client written in Java.
Everything was working fine till this moment. Every time when I added a new row into a table, my auto incrementing Primary Key (numeric id) was finely raised by 1 and a row was added. Now, every time when I freshly start a client and I add a data row into a table via client (does not matter which one - both do the same mess), id is raised to the closest 51 (i.e. last id was 303, so after adding, the id of the new row in the table is 351). If my client is still running since the last addition and I add the next row, it works fine: the next id is 352. It continues without problems till I restart my client. When I add a new row after restarting client, it does the same stuff again: raising id to the closest 51 and then raising but 1.
Is this some kind of bug due to relation of Java and MySQL? This has never happened to me before when I used PHP.
EDIT: For manipulating with database I am using ORM technique via EclipseLink (QuestionDAO.java
):
This is what I do in my data layer when I am adding a question:
public void add( Question q )
{
em . persist(q);
}
This is what I do in my business layer when I am calling a method from data layer (Facade.java
):
public String addQuestion( String text, String subject )
{
Subject s = subjectDAO.find( subject );
if( s != null )
{
Question q = new Question( text, s );
questionDAO . add(q);
return "Question successfully added";
}
else
return "Subject does not exist";
}
Also here is a method from REST:
@POST
@Path("add")
public String add( @FormParam("text") String text, @FormParam("subject") String subject )
{
String s = facade.addQuestion(text, subject);
return s;
}
Annotations in my Entity class:
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Basic(optional = false)
@Column(name = "question_number")
private Integer questionNumber;
I do not believe that a mistake is in my code yet.