How to Create a Primary Key Column With Sequence Generated Value in Hibernate
For example you have a class User: package org.kalidad.seamexercises.model; import java.io.Serializable; import javax.persistence.Co...
https://www.czetsuyatech.com/2011/08/java-persistence-create-primary-key.html
For example you have a class User:
package org.kalidad.seamexercises.model; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.SequenceGenerator; import javax.persistence.Table; @Entity @Table(name = "USER") @SequenceGenerator(sequenceName = "USER_SEQ_ID_GENERATOR", name = "USER_SEQ_ID_GENERATOR") public class User implements Serializable { private static final long serialVersionUID = 4707868996148508582L; private long id; private String name; private String username; private String password; public User() { } @Column(name = "ID") @javax.persistence.Id @GeneratedValue(generator = "USER_SEQ_ID_GENERATOR") public long getId() { return id; } public void setId(long id) { this.id = id; } @Column(name = "NAME") public String getName() { return name; } public void setName(String name) { this.name = name; } @Column(name = "USERNAME") public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } @Column(name = "PASSWORD") public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
Post a Comment