1

I'm setting up a table/entity to auto-generate int values in the first column of a table which will most likely just be the primary key for now in Eclipse with MySQL. It looks like I have it set up correctly with:

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

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(unique=true, nullable=false)
private int id;

It's connecting to the database fine and actually persisting values to the non ID part. The problem is that it's not generating anything for the id. The mysql has a default value of '0' that it's placing in the id column. I'm not getting any errors it just fills the column with '0'.

1 Answer 1

1

When you use a generation type of IDENTITY you tell JPA the database will do the id generation. So you will have to setup the column to use AUTO_INCREMENT.

Sign up to request clarification or add additional context in comments.

1 Comment

That was it. I thought that JPA would some how "handle" this since I indicated my intent through annotation. But the mySQL AUT_INCREMENT works fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.