Upgrading from 1.2 to 2.x

Hi,

Trying to upgrade to latest and greatest and going through motions… from 1.2.1 and document journey… to 2.0 and … hopefully help others

first step upgrading from 1.2.1 to 1.3.3 getting error on Saga Repository

Spring config editor in eclipse showing following error.

No constructor with 0 arguments defined in class ‘org.axonframework.saga.repository.jpa.JpaSagaRepository’

  • No constructor with 0 arguments defined in class

‘org.axonframework.saga.repository.jpa.JpaSagaRepository’

Checked docs but nothing jumped at me to fix this. Any thoughts… Cheers

First learning…

EntityManagerProvider needed as constructor, created simple based on one from util package

@Component

public class MyEntityManagerProvider implements EntityManagerProvider {

@PersistenceContext

private EntityManager entityManager;

@Override

public EntityManager getEntityManager() {

return entityManager;

}

}

Constructor added as ref to the SagaRepository config

Had a EventStoreModule for custom XStream converters needed to modify that creation to include EntityManagerProvider in JPAEventStore constructor

@Configuration

public class EventStoreModule {

public EventStoreModule(){

}

@Autowired

@Named(“myEntityManagerProvider”)

EntityManagerProvider entityManagerProvider;

@Bean(name=“eventStore”)

public JpaEventStore eventStore() {

XStreamEventSerializer eventSerializer = new XStreamEventSerializer();

XStream xStream = eventSerializer.getXStream();

xStream.registerConverter(new JodaMoneyConverter());

xStream.registerConverter(new NamedObjectConverter());

JpaEventStore eventStore = new JpaEventStore(entityManagerProvider, eventSerializer);

return eventStore;

}

}

This seems to have upgraded to 1.3.3 now on to 1.4…
Cheers

Ok… 1.4 upgrades to Quartz2.0, anybody has tips for upgrade… we use Quartztable maker script with quartz 1.8.4… this was a hack we did long time ago… as part of app build in same db to keep things simple and contained… need to figure out how to upgrade this to 2.0…

and also seeing the following error

Initialization of bean failed; nested exception is org.axonframework.util.AxonConfigurationException: Unable to wrap annotated handler.

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)

at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384)

at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)

at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)

at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:543)

at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)

Need to research

Cheers…

Any thoughts, tips… will continue digging… Cheers…

Need some help… looks like all commandhandlers and event handlers throwing this error, must be missing something significant… Upgraded app to Spring 3.1.1 and thought could be AOP related, but not working… Any thoughts, ideas… cheers…Thanks…

Deep nested error in stack trace with more relevance below…

java.lang.IllegalArgumentException: IntroductionAdviceSupport implements no interfaces

at org.springframework.aop.support.DefaultIntroductionAdvisor.(DefaultIntroductionAdvisor.java:73)

at org.springframework.aop.framework.AdvisedSupport.addAdvice(AdvisedSupport.java:404)

at org.springframework.aop.framework.AdvisedSupport.addAdvice(AdvisedSupport.java:393)

at org.axonframework.util.AbstractAnnotationHandlerBeanPostProcessor.createJavaProxyInvoker(AbstractAnnotationHandlerBeanPostProcessor.java:100)

at org.axonframework.util.AbstractAnnotationHandlerBeanPostProcessor.postProcessAfterInitialization(AbstractAnnotationHandlerBeanPostProcessor.java:78)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:407)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1461)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)

at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)

at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)

at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)

Hi,

sorry for the late reply. I am currently abroad and have limited access to the (almost-ubiquitous) internet.

The problem you’re facing seems to be related to Spring’s proxying mechanism. Do you have CGLib on the classpath? Spring resorts to JavaProxies if it cannot be found. In some cases, you also need to specify proxy-target-class=“true” in the component-scan element (or some other elements that allow that to be set).

That should solve the issue of the annotated handlers not being constructed properly. Which Spring version do you use?

Unfortunately, I do not know how to migrate a Quartz 1 to a version 2 store. For the more recent Axon 1 releases, there is a quartz backport that allows you to keep using Axon 1. I did not do the same for Axon 2.

Cheers,

Allard

Hi… thanks for suggestion… however still cannot get it to work… the spring versions is 3.1.1.RELEASE and also have cglib 2.2 in classpath.

The irony is that this setup works perfectly with 1.3.3 and not with 1.4.

Will continue to dig…can’t get it to work .The project is completely mavenized and the only difference in pom is axon version. I did to the diffs between 1.3.3 and 1.4 and so see a difference in the proxy class post processing of Axon in code below. What is intriguing is that this code change is what seems to be where error coming. Also all other annotations are working fine e.g hibernate

at org.axonframework.util.AbstractAnnotationHandlerBeanPostProcessor.createJavaProxyInvoker(AbstractAnnotationHandlerBeanPostProcessor.java:100)

1.3.3

  • @Override
    • public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException {
    • Class<?> targetClass = bean.getClass();
    • if (isPostProcessingCandidate(targetClass)) {
    • Subscribable adapter = initializeAdapterFor(bean);
    • managedAdapters.put(beanName, adapter);
    • return createAdapterProxy(targetClass, bean, adapter, getAdapterInterface());
    • }
    • return bean;
    • }

1.4

  • @Override
    • public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException {
    • Class<?> targetClass = bean.getClass();
    • if (isPostProcessingCandidate(targetClass)) {
    • Subscribable adapter = initializeAdapterFor(bean);
    • managedAdapters.put(beanName, adapter);
    • return createAdapterProxy(targetClass, bean, adapter, getAdapterInterface(), true);
    • } else if (isPostProcessingCandidate(AopProxyUtils.ultimateTargetClass(bean))) {
    • // Java Proxy, find target and inspect that instance
    • try {
    • Object targetBean = ((Advised) bean).getTargetSource().getTarget();
    • // we want to invoke the Java Proxy if possible, so we create a CGLib proxy that does that for us
    • Object proxyInvokingBean = createJavaProxyInvoker(bean, targetBean);

One error deeper below after traversing through the axon function is where this function of createJavaProxyInvoker is looking for an interface on POJO, which does not exist by design. Not sure whey its looking for interfaces.? This was introduced in 1.4.

Caused by: java.lang.IllegalArgumentException: IntroductionAdviceSupport implements no interfaces

at org.springframework.aop.support.DefaultIntroductionAdvisor.(DefaultIntroductionAdvisor.java:73)

at org.springframework.aop.framework.AdvisedSupport.addAdvice(AdvisedSupport.java:404)

at org.springframework.aop.framework.AdvisedSupport.addAdvice(AdvisedSupport.java:393)

Hi,

this afternoon (western european time) I expect to have some time to dive into this. In the meantime, did you try adding the proxy-target-class attribute to a spring component-scan, context:annotation-driven or tx:annotation-driven element? I haven’t seen this issue before, and there must be something simple to resolve it, or at least work around it.

The problem seems to be related to Spring using the java proxying method, which only works on interfaces. I’ll have a look at this as well.

To be continued…

Allard

Thank you so much Allard… I think I may have a solution related to conflicting jars in maven dependency… So don’t spend any of your time till I get back… Cheers and Thanks again…

Hi,

that’s actually good news, because I didn’t mange to reproduce the problem yet. I didn’t manage to create a configuration in which you get a Java Proxy in spring for a class that doesn’t implement any interface.

Keep me updated in case you find the solution.

Cheers,

Allard

OK… I think this is the issue… axon infrastructure config spring xml had these two settings from a long time

<bean

class=“org.axonframework.eventhandling.annotation.AnnotationEventListenerBeanPostProcessor”>

<bean

class=“org.axonframework.commandhandling.annotation.AnnotationCommandHandlerBeanPostProcessor”>

Commented these out and thats when error disappeared and become normal. These seemed to be kicking into JavaProxys with the declaration even when they were not supposed to… Not sure why though?

Cheers and thanks again for all the help… now need to do more testing and then prep for moving to 2.0… the big change

Does that mean you had the ‘manual’ post processors configured, as well as an axon:annotation-config element?
If not, doublecheck whether your event listeners and command handlers are working properly.

Cheers,

Allard

Yes both of these were in axon infrastructure config

<axon:annotation-config command-bus=“commandBus”

executor=“taskExecutor” />

<axon:event-bus id=“eventBus” />

<bean

class=“org.axonframework.eventhandling.annotation.AnnotationEventListenerBeanPostProcessor”>

<bean

class=“org.axonframework.commandhandling.annotation.AnnotationCommandHandlerBeanPostProcessor”>

Still cannot understand why this would break it in 1.4? as it worked very well upto 1.3.3.

Cheers and Thanks…

Hi,

thanks for the info. I’ll fix this issue in 2.x. I have created issue AXON-119 (http://issues.axonframework.org/youtrack/issue/AXON-119) for it.

The reason is doesn’t work in 1.4 anymore is that 1.4 deals with proxies, which could occur when you use libraries like Spring-Security to secure certain methods. To make sure that even Command and Event Handlers can be annotated with these security annotations, Axon needs to be able to work with proxied objects.

The problem is dat the post processors proxy the beans themselves as well. So by adding two post processors, the second recognizes the proxy and will attempt to proxy it again, which fails.

Cheers,

Allard

Great Thanks… Ok… now working on getting to Axon2.0… seeing AggregateIdentifier initialization issues in certain scenario… one scneario is as follows

Aggregate initializes and fires several events in constructor… has been working perfecty upto 1.4. Now the problem is event 1 goes to outside domain, event two is the one which is handled by aggregate and initializes its aggregateIdentifier, however from the external domain there is another incoming call to the aggregate.

Before the auper(aggregateIdentifier) of AbstractAnnotatedAggregateRoot took care of this scenario. I will dig deeper and try to get more color. Please let me know if anything jumps out.

The situation again is

  • constructor has logic to analyze variables and fire thirparty domain events
  • then fire initailization event which is handled by aggregate and where this.id = event.getAggrregateId is set

Now am getting

AggregateIdentifier is unknown in. Make sure the Aggregate Identifier is initialized before registering events.

at org.axonframework.domain.AbstractAggregateRoot.getEventContainer(AbstractAggregateRoot.java:163)

at org.axonframework.domain.AbstractAggregateRoot.registerEvent(AbstractAggregateRoot.java:72)

at org.axonframework.eventsourcing.AbstractEventSourcedAggregateRoot.apply(AbstractEventSourcedAggregateRoot.java:96)

at org.axonframework.eventsourcing.AbstractEventSourcedAggregateRoot.apply(AbstractEventSourcedAggregateRoot.java:75)

Before aggregate would get initialized with super… Any thoughts… I will dig deeper… however wanted to see if anything pops out.

Ok some more color, now if i rearrage the events to have the first one which initializes the aggregate and if 2 or more events fire in constructor am getting this

java.lang.IllegalArgumentException: Unsuitable aggregate for this repository: wrong type

at org.axonframework.common.Assert.isTrue(Assert.java:52)

at org.axonframework.repository.AbstractRepository.add(AbstractRepository.java:62)

at org.axonframework.repository.LockingRepository.add(LockingRepository.java:80)

This constructor logic works perfectly working fine in 1.4… so a lot of logic is tied to this strategy and it working before… Looks like stuck… anything pops, ideas… thoughts

Thanks and Cheers…

Hi,

the first event of an aggregate must always set the identifier. Otherwise, Axon can’t know what the ID of an aggregate is.

The problem you’re encountering is probably a configuration bug in your application, which wasn’t detected in 1.4. Since Axon 2, a repository checks whether the aggregate you pass into it is actually an instance of the type te repository stores. It seems that this is not the case here.
Make sure the right repository instance is injected into your command handler.

Cheers,

Allard

My bad… the rearranging seems to made things move forward… the wrong type error was my mistake in refactoring the axon:event-sourcing-repository to wrong type… so please dont worry about the wrong type error… Lot more to do… Stay tuned…Thanks and Cheers…

Ok… now having core snapshotter errors… looks like the snapshotter is not working when the time comes to snapshot… this is not giving too much info… snapshotter config and repository which is throwing errors is as follows and the error stack is also below… old config had standard spring beans, now moved to axon tags based configuration.

<axon:snapshotter id=“snapshotter”

event-store=“eventStore”

executor=“taskExecutor”

transaction-manager=“transactionManager”/>

<axon:event-sourcing-repository id=“myAggregateRepository”

aggregate-type=“com.fp.server.MyAggregate” event-bus=“eventBus”

event-store=“eventStore” >

<axon:snapshotter-trigger snapshotter-ref=“snapshotter”

event-count-threshold=“5” />

</axon:event-sourcing-repository>

<bean id=“entityManagerFactory”

class=“org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean”>

<bean id=“dataSource”

class=“org.springframework.jdbc.datasource.IsolationLevelDataSourceAdapter”>

in persistence.xml

org.hibernate.ejb.HibernatePersistence…

ERROR

2013-04-07 13:57:20,669 [taskExecutor-2] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: null

2013-04-07 13:57:20,669 [taskExecutor-2] ERROR org.hibernate.util.JDBCExceptionReporter - failed batch

2013-04-07 13:57:20,669 [taskExecutor-2] WARN org.axonframework.eventsourcing.AbstractSnapshotter - An attempt to create and store a snapshot resulted in an exception. Exception summary: {}

javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update

at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)

at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1315)

at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:255)

at org.axonframework.eventstore.jpa.DefaultEventEntryStore.findRedundantSnapshots(DefaultEventEntryStore.java:126)

at org.axonframework.eventstore.jpa.DefaultEventEntryStore.pruneSnapshots(DefaultEventEntryStore.java:97)

at org.axonframework.eventstore.jpa.JpaEventStore.appendSnapshotEvent(JpaEventStore.java:254)

at org.axonframework.eventsourcing.AbstractSnapshotter$CreateSnapshotTask.run(AbstractSnapshotter.java:90)

at org.axonframework.eventsourcing.SpringAggregateSnapshotter$TransactionalRunnableWrapper.run(SpringAggregateSnapshotter.java:137)

at org.axonframework.eventsourcing.AbstractSnapshotter$SilentTask.run(AbstractSnapshotter.java:145)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)

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

at java.lang.Thread.run(Thread.java:680)

Caused by: org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update

at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)

at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)

at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)

at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)

at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:268)

at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)

at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)

at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:64)

at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1185)

at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1261)

at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)

at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:246)

… 9 more

Caused by: java.sql.BatchUpdateException: failed batch

at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)

at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(Unknown Source)

at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)

at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)

at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)

… 17 more