cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <>
Subject Re: Controlling Cayennes JDBC connection usage
Date Mon, 09 Oct 2017 06:29:22 GMT
Hi Dirk,

When using explicit transactions [1], the connection is always the same within the transaction.
"runtime.performInTransaction(..)" [2] can also take TransactionListener as a second argument
that you may implement to set connection properties. 

Unrelated to the above, specifically for schema generation purposes you can bind SchemaUpdateStrategyFactory
[3] when you start your runtime, that creates SchemaUpdateStrategy (either one of the standard
choices like CreateIfNoSchemaStrategy, or your custom version). Cayenne is guaranteed to invoke
the strategy before any of the app code can access the DB.

Hopefully it will point you in the right direction.



> On Oct 8, 2017, at 12:39 PM, Dirk Lattermann <> wrote:
> Hello,
> is it possible to control which database connection is used when
> committing an ObjectContext?
> For example, when using an explicit transaction, the database
> connection used in the thread starting the exception must always be the
> same.
> Now, I have a use case where I want to obtain a PostgresQL advisory
> exclusive session lock and do some DDL to create a db schema. Then I
> want to write something into that schema using Cayenne, and after that,
> release the lock. That's to somewhat atomically initialize a db schema.
> For normal schema usage, I want to obtain an advisory shared lock in the
> db connection and use that connection with Cayenne.
> That mechanism can also be used to manipulate portions of the database
> that must be done without concurrent access.
> It's how I solved the problem with Hibernate, where a Hibernate session
> represents a JDBC Connection. It is bound to the current thread and
> used for all Hibernate DB accesses during the session. That worked
> quite well.
> Would it be possible to do something similar with Cayenne?

View raw message