CDILiquibase not reliable working

Hello together,



hopefully someone can help me?



I have following code, which is failing on startup:



@Dependent
@NoArgsConstructor
@Slf4j
public
class InitSystemLiquibase {

/** the {@link DataSource}. */

@Resource(name = DataSourceConstants.JNDI_NAME_REDD_DS)

private transient DataSource dataSource;
/**

  • Create the DB config/schema.

  • @return {@link CDILiquibaseConfig}
    */
    @Produces
    @LiquibaseType

public CDILiquibaseConfig createConfig() {

LOG.info(“starting Liquibase execution.”);

CDILiquibaseConfig lConfig = new CDILiquibaseConfig();
lConfig.setChangeLog(DataSourceConstants.LIQUIBASE_MASTERCHANGELOG);

return lConfig;
}

/** create the datasource for the CDI.
*

  • @return the {@link DataSource}
    */
    @Produces
    @LiquibaseType

public DataSource createDataSource() {

return dataSource;
}
/**

  • Create the classloader.

  • @return The {@link ResourceAccessor}
    */
    @Produces
    @LiquibaseType

public ResourceAccessor create() {

LOG.debug(“getting the classloader”);

ResourceAccessor lResult = null;

ClassLoader lLoader = Thread.currentThread().getContextClassLoader();

lResult = new ClassLoaderResourceAccessor(lLoader);

//TODO: added to test classloading of the packaged db-addons, else
this call is fully useless

//new WildflyClasspathWorarkoundDriver();

return lResult;
}
}
My issue now is, that my Liquibase is failing on startup of the
application with following exception:



org.jboss.weld.exceptions.WeldException:
WELD-000049: Unable to invoke public void
liquibase.integration.cdi.CDILiquibase.onStartup() on liquibase.integ
ration.cdi.CDILiquibase@ae5f6f6

at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:100)

at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.postConstruct(DefaultLifecycleCallbackInvoker.java:81)

at org.jboss.weld.injection.producer.BasicInjectionTarget.postConstruct(BasicInjectionTarget.java:126)

at org.jboss.weld.injection.producer.BeanInjectionTarget.postConstruct(BeanInjectionTarget.java:70)

at liquibase.integration.cdi.CDIBootstrap$1.create(CDIBootstrap.java:95)

at liquibase.integration.cdi.CDIBootstrap$1.create(CDIBootstrap.java:38)

at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:96)

at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:98)

at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:78)

at
liquibase.integration.cdi.CDILiquibase$Proxy$_$$_WeldClientProxy.toString(Unknown Source)

at liquibase.integration.cdi.CDIBootstrap.afterDeploymentValidation(CDIBootstrap.java:111)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:497)

at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:90)

at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:271)

at org.jboss.weld.event.ExtensionObserverMethodImpl.sendEvent(ExtensionObserverMethodImpl.java:121)

at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:258)

at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:237)

at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:174)

at org.jboss.weld.event.ObserverNotifier.notifyObservers(ObserverNotifier.java:133)

at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:107)

at org.jboss.weld.bootstrap.events.AbstractContainerEvent.fire(AbstractContainerEvent.java:54)

at org.jboss.weld.bootstrap.events.AbstractDeploymentContainerEvent.fire(AbstractDeploymentContainerEvent.java:35)

at org.jboss.weld.bootstrap.events.AfterDeploymentValidationImpl.fire(AfterDeploymentValidationImpl.java:28)

at org.jboss.weld.bootstrap.WeldStartup.validateBeans(WeldStartup.java:439)

at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:90)

at org.jboss.as.weld.WeldStartService.start(WeldStartService.java:93)

at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)

at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

at java.lang.Thread.run(Thread.java:745)
Caused
by: java.lang.reflect.InvocationTargetException

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:497)

at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:98)

… 33 more
Caused
by: liquibase.exception.UnexpectedLiquibaseException:
liquibase.exception.MigrationFailedException: Migration failed for
change set liquibase/001_CreateUsers.xml::001_CreateUsers_DefaultTable::me:

Reason: liquibase.exception.DatabaseException: Error creating or
initializing trigger
\“MODIFY_ROWCREATED_ROWUPDATED_TRIGGER\” object, class
\“com.x.db.h2.ModifyRowCreatedRowUpdatedTrigger\”,
cause: \“org.h2.message.DbException: Class
\”\“com.x.db.h2.ModifyRowCreatedRowUpdatedTrigger\”\"
not found [90086-173]\"; see root cause for details; SQL statement:
CREATE
TRIGGER IF NOT EXISTS modify_rowCreated_rowUpdated_trigger BEFORE
INSERT ON Users FOR EACH ROW CALL
\“com.x.db.h2.ModifyRowCreatedRowUpdatedTrigger\”
[90043-173] [Failed SQL: CREATE TRIGGER IF NOT EXISTS
modify_rowCreated_rowUpdated_trigger BEFORE INSERT ON Users FOR EACH
ROW CALL \“com.x.db.h2.ModifyRowCreatedRowUpdatedTrigger\”]

at liquibase.integration.cdi.CDILiquibase.onStartup(CDILiquibase.java:118)

… 38 more
Caused
by: liquibase.exception.MigrationFailedException: Migration failed
for change set liquibase/001_CreateUsers.xml::001_CreateUsers_DefaultTable::me:

Reason: liquibase.exception.DatabaseException: Error creating or
initializing trigger
\“MODIFY_ROWCREATED_ROWUPDATED_TRIGGER\” object, class
\“com.x.db.h2.ModifyRowCreatedRowUpdatedTrigger\”,
cause: \“org.h2.message.DbException: Class
\”\“com.x.db.h2.ModifyRowCreatedRowUpdatedTrigger\”\"
not found [90086-173]\"; see root cause for details; SQL statement:
CREATE
TRIGGER IF NOT EXISTS modify_rowCreated_rowUpdated_trigger BEFORE
INSERT ON Users FOR EACH ROW CALL
\“com.x.db.h2.ModifyRowCreatedRowUpdatedTrigger\”
[90043-173] [Failed SQL: CREATE TRIGGER IF NOT EXISTS
modify_rowCreated_rowUpdated_trigger BEFORE INSERT ON Users FOR EACH
ROW CALL \“com.x.db.h2.ModifyRowCreatedRowUpdatedTrigger\”]

at liquibase.changelog.ChangeSet.execute(ChangeSet.java:584)

at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:51)

at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:73)

at liquibase.Liquibase.update(Liquibase.java:210)

at liquibase.Liquibase.update(Liquibase.java:190)

at liquibase.integration.cdi.CDILiquibase.performUpdate(CDILiquibase.java:129)

at liquibase.integration.cdi.CDILiquibase.onStartup(CDILiquibase.java:116)

… 38 more


If I execute the scripts with ANT and this JDBC driver:

driverclasspath=“org.postgresql.Driver”

jdbcUrl=“jdbc:postgresql://10.1.2.12/mydb”





Everything is working fine.

So I tried also as workaround to populate FIRST the database with
liquibase before starting my wildfly, and I am still getting the issue,
that my H2 classes are pulled instead of the Postgres simpler triggers.



And here the changeset parts:

CREATE OR REPLACE FUNCTION

modify_rowCreated_rowUpdated() RETURNS trigger

LANGUAGE plpgsql

AS $$
DECLARE

current_ts timestamp;
BEGIN

current_ts := CURRENT_TIMESTAMP;

NEW."rowCreated" := current_ts;

NEW."rowUpdated" := current_ts;

RETURN NEW;
END;
$$;

CREATE OR REPLACE FUNCTION

modify_rowUpdated() RETURNS trigger

LANGUAGE plpgsql

AS $$
BEGIN

NEW."rowUpdated" := CURRENT_TIMESTAMP;

RETURN NEW;
END;
$$;

DROP TRIGGER IF EXISTS
"modify_rowCreated_rowUpdated_trigger" ON
"${table.name}" ;

CREATE TRIGGER
"modify_rowCreated_rowUpdated_trigger" BEFORE
INSERT ON "${table.name}" FOR EACH ROW EXECUTE
PROCEDURE modify_rowCreated_rowUpdated();

DROP TRIGGER IF EXISTS "modify_rowUpdated_trigger"
ON "${table.name}";

CREATE TRIGGER "modify_rowUpdated_trigger" BEFORE
UPDATE ON "${table.name}" FOR EACH ROW EXECUTE
PROCEDURE modify_rowUpdated();

CREATE TRIGGER IF NOT EXISTS modify_rowCreated_rowUpdated_trigger
BEFORE INSERT ON ${table.name} FOR EACH ROW CALL "com.x.db.h2.ModifyRowCreatedRowUpdatedTrigger";

CREATE TRIGGER IF NOT EXISTS modify_rowUpdated_trigger BEFORE UPDATE
ON ${table.name} FOR EACH ROW CALL "com.x.db.h2.ModifyRowUpdatedTrigger";

Can someone help me out of the dark?



Versions:

Liquibase 3.4.1

Wildfly 8.2.0

JDK 1.8.0_45



best wishes,

Darko

Really no help on this issue?

Thank you for your response.
Will try it on SO

Independently:
Can you recommend us how to get rid of the CDI and to integrate it into the EJB container on startup, without CDI?
Also, is there a way to suppress the CDI of liquibase to get automatically started?
As soon as the liquibase-cdi is part of the classpath, we have to implement the CDI configuration.

best wishes

You might have more luck posting this to StackOverflow, tagging it with liquibase and wildfly.

Steve Donie
Principal Software Engineer
Datical, Inc. http://www.datical.com/

I personally have no familiarity at all with CDI, so I can’t really help.

Steve Donie
Principal Software Engineer
Datical, Inc. http://www.datical.com/

Again, not something in my realm of expertise. There may be other people here who can answer, but I would suggest that StackOverflow probably gets more traffic, especially around EJB containers and Liquibase.

Steve Donie
Principal Software Engineer
Datical, Inc. http://www.datical.com/

Looking at the code for CDILiquibase, it checks the liquibase.shouldRun flag and if it is false, it does not execute.

Your easiest route would be to either set the liquibase.shouldRun system property to “false”, or call

  1. LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.).setShouldRun(false)
from somewhere in your code that executes before the CDI bootstrapping happens, possibly in a class's static{} block?

Nathan

Nathan

Hello Steve,

thanks for your reply. The question was not to CDI it was how to get rid the CDI.
Means what type of startup in a EJB containter do you suggest?
I know this: http://www.liquibase.org/documentation/running.html

Means are the more options of integrating it directly into a EJB (without CDI)?

best wishes