Sometimes I find them together, sometimes alone... other times they seem to do the same.
What's the difference?
Here are three examples. What do they do of different? Why can't I use just @GeneratedValue for all of them?
Example 1
@Id
@GeneratedValue(generator="increment")
@GenericGenerator(name="increment", strategy = "increment")
Long id;
Example 2
@Id @GeneratedValue(strategy=GenerationType.SEQUENCE)
private int userId;
Example 3
@ElementCollection
@JoinTable(name="Address",
joinColumns=@JoinColumn(name="user_id")
)
@GenericGenerator(name="hilo-gen", strategy="hilo")
@CollectionId(columns = @Column(name="Address_id"), generator = "hilo-gen", type = @Type(type="long"))
Collection<Addr> listOfAddresses = new ArrayList<Addr>();