Also, just noticed you are not subscribed to the list, and the reply to address 
was invalid, so resending to what I think is the correct address.

A.


> On Sep 24, 2025, at 4:08 PM, Andrus Adamchik <[email protected]> wrote:
> 
> Hi Ricardo,
> 
> In addition to what John said, you should be able to specify custom names in 
> the Modeler by using "Custom Sequence". I've never done it myself, as all my 
> PKs are auto-increments (aka "Database-Generated") or set explicitly. But the 
> feature is there and should work.
> 
> Andrus
> 
> 
> 
>> On Sep 24, 2025, at 4:01 PM, John Huss <[email protected]> wrote:
>> 
>> Cayenne-Generated (Default) works for this. By default cayenne uses
>> sequences named "PK_<ENTITY>", so "PK_CLAIM" in your example. So if you
>> have existing sequences you'd like to use instead you have to override it
>> to use your naming scheme, by adding these classes.
>> 
>> import java.sql.Types;
>> 
>> import java.util.ArrayList;
>> 
>> import java.util.HashMap;
>> 
>> import java.util.Iterator;
>> 
>> import java.util.List;
>> 
>> import java.util.Map;
>> 
>> import java.util.Optional;
>> 
>> 
>> import org.apache.cayenne.CayenneRuntimeException;
>> 
>> import org.apache.cayenne.access.types.ExtendedType;
>> 
>> import org.apache.cayenne.access.types.ExtendedTypeFactory;
>> 
>> import org.apache.cayenne.access.types.ValueObjectTypeRegistry;
>> 
>> import org.apache.cayenne.configuration.Constants;
>> 
>> import org.apache.cayenne.configuration.RuntimeProperties;
>> 
>> import org.apache.cayenne.dba.PkGenerator;
>> 
>> import org.apache.cayenne.dba.QuotingStrategy;
>> 
>> import org.apache.cayenne.dba.TypesMapping;
>> 
>> import org.apache.cayenne.dba.postgres.PostgresAdapter;
>> 
>> import org.apache.cayenne.di.Inject;
>> 
>> import org.apache.cayenne.map.DbAttribute;
>> 
>> import org.apache.cayenne.map.DbEntity;
>> 
>> import org.apache.cayenne.resource.ResourceLocator;
>> 
>> 
>> public class EOPostgresAdapter extends PostgresAdapter {
>> 
>> 
>> public EOPostgresAdapter(@Inject RuntimeProperties runtimeProperties,
>> 
>> @Inject(Constants.SERVER_DEFAULT_TYPES_LIST) List<ExtendedType>
>> defaultExtendedTypes,
>> 
>> @Inject(Constants.SERVER_USER_TYPES_LIST) List<ExtendedType>
>> userExtendedTypes,
>> 
>> @Inject(Constants.SERVER_TYPE_FACTORIES_LIST) List<ExtendedTypeFactory>
>> extendedTypeFactories,
>> 
>> @Inject ResourceLocator resourceLocator,@Inject ValueObjectTypeRegistry
>> valueObjectTypeRegistry) {
>> 
>> super(runtimeProperties, defaultExtendedTypes, userExtendedTypes,
>> extendedTypeFactories, resourceLocator, valueObjectTypeRegistry);
>> 
>> }
>> 
>> 
>> @Override
>> 
>> protected PkGenerator createPkGenerator() {
>> 
>> return new EOPostgresPkGenerator(this);
>> 
>> }
>> 
>> }
>> 
>> 
>> 
>> import org.apache.cayenne.dba.JdbcAdapter;
>> 
>> import org.apache.cayenne.dba.postgres.PostgresPkGenerator;
>> 
>> import org.apache.cayenne.map.DbEntity;
>> 
>> 
>> public class EOPostgresPkGenerator extends PostgresPkGenerator {
>> 
>> 
>> public EOPostgresPkGenerator() {
>> 
>> super();
>> 
>> }
>> 
>> public EOPostgresPkGenerator(JdbcAdapter adapter) {
>> 
>> super(adapter);
>> 
>> }
>> 
>> 
>> @Override
>> 
>> protected String getSequencePrefix() {
>> 
>> return "";
>> 
>> }
>> 
>> @Override
>> 
>> protected String sequenceName(DbEntity entity) {
>> 
>> return super.sequenceName(entity) + "_seq";
>> 
>> }
>> 
>> }
>> 
>> 
>> 
>> 
>> Then, to install the overridden classes would do something like this:
>> 
>> 
>> ServerRuntime.builder().addConfig("cayenne-MyDomain.xml").addModule(new
>> Module() {
>> 
>> public void configure(Binder binder) {
>> 
>> binder.bind(PkGenerator.class).to(EOPostgresPkGenerator.class);
>> 
>> binder.bind(DbAdapter.class).to(EOPostgresAdapter.class);
>> 
>> }
>> 
>> }).build();
>> 
>> 
>> 
>> On Wed, Sep 24, 2025 at 1:31 PM Ricardo Parada <[email protected]>
>> wrote:
>> 
>>> Hello all,
>>> 
>>> I haves beginner’s question.
>>> 
>>> We have an Oracle database which we currently use with Apple’s Enterprise
>>> Objects Framework (EOF).
>>> 
>>> For every table name, e.g. ORDER there is a sequence derived from the
>>> table name and spending “_SEQ”, e.g. CLAIM_SEQ.
>>> 
>>> How is this handled in Cayenne normally? Will it derive the sequence name
>>> correctly?
>>> 
>>> The modeler gives me three options:
>>> 
>>> Cayenne-Generated (Default)
>>> Database-Generated
>>> Custom Sequence
>>> 
>>> Which one would be the right one for this database?
>>> 
>>> Thank you
>>> Ricardo Parada
> 

Reply via email to