If you like to generate identifiers that are shared (and unique) between multiple stored objects, use @TableGenerator. H2 and many other databases do not have internal sequence support, so @SequenceGenerator does not work.
Here is a quick example to have a unique / shared @Id through two objects:
@Entity public class Class1 { // setting pkColumnValue of TableGenerator is very important ;-) @Id @TableGenerator( name = "guid", initialValue = 0, allocationSize = 10, table = "GUID_SEQ", pkColumnName = "GEN_KEY", valueColumnName = "GEN_VALUE", pkColumnValue = "GUID") @GeneratedValue(strategy = GenerationType.TABLE, generator = "guid") private long id; } @Entity public class Class2 { // use the same pkColumnValue @Id @TableGenerator( name = "guid", initialValue = 0, allocationSize = 10, table = "GUID_SEQ", pkColumnName = "GEN_KEY", valueColumnName = "GEN_VALUE", pkColumnValue = "GUID") @GeneratedValue(strategy = GenerationType.TABLE, generator = "guid") private long id; }
source share