-
1. ID Generation - best practices?
wdfink Apr 15, 2011 7:16 AM (in response to djhill)Best practice - depends to your environment.
If you use @Id and @GeneratedValue the container decide how to do it depended to the database, e.g. autoincrement DB fields.
We use
@Entity
@SequenceGenerator(name = "MySequence", sequenceName = "MY_SEQ", initialValue = 1, allocationSize = 1)
class MyClazz {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "MySequence")
long myPk;
}
because of use Oracle and defined DB sequences.
-
2. ID Generation - best practices?
djhill Apr 15, 2011 10:12 AM (in response to wdfink)Thanks, Wolf-Dieter.
That was the strategy applied to the one table in the original code, and it does simplify coding. But because the ID_GEN table was also present, I couldn't tell if the original author was planning to go in one direction or the other. For that one entity (Salary), Hibernate created a sequence and a table DUAL_SALARY_SEQ, so I have to assume that similar sequences and tables would be created for all entities, possibly resulting in a proliferation of SEQ tables.
I'd be curious to hear whether a single table (which is likely to be cached) might offer better performance. Has anyone compared the two?