This is an upper level design question associated with how to best generate a unique value using Cayenne and MySQL.

Step 1:
I have an existent Entity with a primary key (oid). Per the Cayenne- recommended best practices I am avoiding direct access of this primary key and have created another attribute (orderID) that must be unique. So upon doing my Cayenne homework I read that the standard behavior in the DBMS model and the ORM model is to support only one auto-generated column and this is typically the PK column not related to my data abstraction.

Step 2:
So then I thought, well I will just use the MySQL "MAX()" function, find the max value, increment and voila I have generate my own unique number. When I tried to implement this design I ran into problems with SQLTemplate query attempting to bind the result of MAX(orderID) to an existent data object.

Step 3:
I guess I could always execute a "select *" on the entity and find the max attribute-value with a "for" loop, but that seems kind of Neanderthal. OK, so I am now thinking someone must have solved this sort of design issue before I bumped into it. What is the best way to solve this issue using Cayenne design patterns?

Thanks,
Joe



Reply via email to