cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: pk generation strategy and multiple databases
Date Wed, 13 Jul 2011 16:05:05 GMT

On Jul 11, 2011, at 11:08 AM, Marcin Skladaniec wrote:

> First, can the datasource info be removed from the cayenne model files alltogether? I've
noticed that in 3.1M2 there is no separate xml file for driver, but the nodes are defined
in the main config file. My brief attempt to just delete that info lead to nowhere, but that
could be just a problem with my setup.

Yes in 3.1 nodes are defined in the main config file. The normal approach to abstracting this
data is via JNDIDataSourceFactory. Or in non-web environments (to avoid manually bootstrapping
JNDI provider), just create a custom DataSourceFactory that would pull DB connection info
in a way appropriate for the app.

> Second, I have an issue with PK generation strategies. Those are defined on the DbEntity
level, which makes sense, but also makes it harder to have different strategies for different
database engines.

True. Changing PK gen strategy in runtime is possible now, but is somewhat involved. I feel
like many things in the mapping would benefit from a more straightforward way of overriding
in runtime. Maybe need a separate DI service for PK gen.

> This also comes down to the documentation onhttp://cayenne.apache.org/doc/primary-key-generation.html.
> In the DatabaseEntity there are 3 options for the PK generation strategy: "Default",
"Database-Generated" and "Custom sequence".
> I understand that Default refers to cayenne generated primary key, but the documentation
mentioned in the last paragraph states, under the section describing database generated pk:
 "Currently MySQL and SQLServer adapters have this feature turned on by default.".
> I'm a little confused what is default anymore, and how cayenne distinguishes the two.

Default is same as before - a per-adapter strategy of generating PK. The above mentioned sentence
is about DB-generated strategy. It is not supported on all DB's due to driver limitations.
So some Cayenne adapters have it on, others don't. 

In general I agree that we may need to add some clarity into PK generation strategies.

> Now finally my real problem, in cayenne generated pk scenario sqlserver is said to use
a stored procedure tied to AUTO_PK_TABLE to manage the primary key. In my application this
procedure is installed manually before the cayenne service startup, I have verified its existence
in the database, but it is never available to cayenne, causing exception attached at the end
of the email.
> What can cause such problem? is that the datasource defined in model? I'm running out
of ideas, any help would be greatly appreciated.

Probably in the wrong schema. I am an infrequent user of SQLServer, but a few times a similar
thing happened to me it was schema related.

Cheers,
Andrus


Mime
View raw message