1

Suppose I have the following situation: I have 5 entities (reduced for the sake of simplicity) of which I unequivocally know that 3 of them will have few records in the database (15-20 or so each). The remaining 2 entities will have a lot of records (thousands) and will also grow rapidly.

Using the default Hibernate ID generation strategy (AUTO), this means that all records will have a unique ID across all entities (because there's only 1 sequence). I'm reluctant towards this, because this means that ID's will grow rapidly because of the large number of records in some tables.

Question #1: can I redefine the ID stragey for the 2 big entities, so that each of those will have its own sequence, and keep the others on AUTO? Is it considered good/bad practice to mix and match ID strategies? Any reasons why I should/shouldn't do this?

Question #2: considering an Oracle 10g database, are there any pros and cons concerning ID generation strategies? For instance; is it better to use TABLE instead of SEQUENCE?

Thanks in advance!

tmbrggmn
  • 8,680
  • 10
  • 35
  • 44

2 Answers2

1

Question #1: There's no problem at all. Each entity class can have it's own ID strategy.

Question #2: Sequences exists mainly to generate surrogate keys. So, use it without fear :-)

jpkroehling
  • 13,881
  • 1
  • 37
  • 39
0

with oracle DBMS I think that you should consider using a sequence for all your entities

  • id generation is so reliable done by DB
  • you have no special case which make your code easier to unterstand
lweller
  • 11,077
  • 3
  • 34
  • 38