Discussions

EJB design: Entity Sequence Block Pattern Opinions

  1. Entity Sequence Block Pattern Opinions (1 messages)

    hi,

    i'm actually a web developer by trade, and am building an EJB component to integrate with a JSF web component. i'm currently working on a sequence block mechanism (like the one described in Marinescu's patterns book) to auto-generate incremental integral primary keys for other entity beans in the project. the whole thing is setup with a stateless session bean acting as the intermediatary between the entity who wants an automatic primary key and the instance that represents the entity's persistent sequential state.

    per Marinescu's discussion, the session bean is configured to retrieve a block of sequential numbers at a time and cache them to minimize calls to the entity. in the book's discussion, size of the sequential block retrieved (i.e. cache 5 numbers or cache 500 numbers) is set in the stateless session bean. the number of retry attempts made after catching a TransactionRolledbackException is set in the session bean as well.

    i started thinking about this, and wondered if the blockSize and retryCount shouldn't also be persistent properties of the sequence. since all entities go through the same stateless session class, you wouldn't be able to change the blockSize or retryCount of a specific entity's sequence. you could possibly pass different parameters to the facade when requesting a new block, but i think that would be a cumbersome task.

    so, i've altered the book's example in my implementation to do just that -- make the blockSize and retryCount persistent attributes of the sequence (along with the initialValue, but that's only used when the sequence is first created). now that i've done it though, i'm wondering whether it was a good idea. don't get me wrong, it works great, but i'm fairly new to ejb and don't know if there could be any drawbacks to my approach. Expert opinions welcome!

    thanks,
    sophomore
  2. so, i've altered the book's example in my implementation to do just that -- make the blockSize and retryCount persistent attributes of the sequence (along with the initialValue, but that's only used when the sequence is first created). now that i've done it though, i'm wondering whether it was a good idea. don't get me wrong, it works great, but i'm fairly new to ejb and don't know if there could be any drawbacks to my approach.
    It depends on what you mean by "persistent property". If you made these values something that you can manage through configuration and initialized in ejbCreate() or ejbSetSessionContext(), then this is fine. If you require a database retrieval to determine blockSize and retryCount every time you create a new key, then this is a bad idea.