Semi-major: at what point in the lifecycle are additional datastores available? (or, "Abstract schema type unknown...")

I have a listener for AppContentStartedEvent which invokes a bean which in turn simply publishes a custom event. The purpose of this is to, at app startup, create some data that is needed for a new instance of the app (if it doesn’t already exist). There are numerous listeners of this event, they all handle what’s needed for an entity.

My latest one needs to copy some master data from a shared/secondary datastore to the main one, if the main one is empty.

It seems that additional datastores are not available during this part of the app lifecycle, as all attempts to refer to the additional store via dataManager.* operations produce a JPQL exception Abstract schema type unknown... Access to the main store work just fine at this point in the lifecycle.

It’s not a persistence.xml issue, as the additional store can be accessed just fine in the normal part of the app.

How can I solve this; at what point in the app cycle is that additional datastore available?

Ok - it is even WEIRDER than I thought.

In the same spot,

                MasterICDCode firstICDCode = dataManager.load(MasterICDCode.class)
                        .query("select i from medflexj_MasterICDCode i").one();
                log.info("*** First ICD Code: {} is {}", firstICDCode.getCode(), firstICDCode.getDescription());

… works just fine, as expected.

BUT, this:

Long masterCount = dataManager.loadValue("select count(i.code) from medflexj_MasterICDCode i", Long.class).one();

Does NOT work, it produces the exception mentioned in the OP. If I use an entity from the main datastore, queries of that form work just fine.

… what is happening here? O_O The entity is available for one type of query but not the other?

Solved. VERY WEIRD, however.

So, apparently, for loadValue queries, at that point in the lifecycle, one needs to add a .store() to the method chain, supplying the store name, and then it works fine. At later points in the lifecycle, the .store() call isn’t needed.

Odd, but that’s the solution.

Hi Jon,

loadValue() always needs .store() to work with entities of an additional data store.
If you can provide a reproducible case when it’s not true, we’ll check and fix it.