The AS7 book!

JBoss Tuning

Top Programming Sites
Home Howto EJB How do you bind the Id of an Entity to a Sequence ?

How do you bind the Id of an Entity to a Sequence ?

jboss recipe of the day
You can define a SequenceGenerator which points to the DB Sequence. Then you link your Id to the SequenceGenerator through the @GeneratedValue annotation. Example:
@Entity

@Table(name="EJB_TASK_VIEWS")

public class View implements Serializable  {

@Id()
@GeneratedValue( strategy=GenerationType.SEQUENCE, generator="viewSequence" )  
@SequenceGenerator( name="viewSequence", sequenceName="VIEW_SEQUENCE")


public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
.....
}
How do you bind the Id of an Entity to a Sequence ?
 

License

Mastertheboss.com Unless stated, all the contents of this site is licensed under Creative Comons License
Licenza Creative Commons