Envers doesn't insert records - spring

I'm trying to integrate Envers in my project. I'm using Hibernate-envers 3.5.5-Final, Hibernate-core 3.5.5-Final, spring 3.0.7.RELEASE.
For DAO Layer, I'm using a GenericDaoHibernate class.
My applicationContext.xml contains:
<property name="eventListeners">
<map>
<entry key="post-insert" >
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
<entry key="post-update">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
<entry key="post-delete">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
<entry key="pre-collection-update">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
<entry key="pre-collection-remove">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
<entry key="post-collection-recreate">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
</map>
</property>
The audit tables for the annotated classes are created, but by adding or updating a row in the entity table, no row is inserted in the _AUD tables or in the REVINFO.
So, I added a new listener org.hibernate.ejb.event.EJB3PostInsertEventListener as :
<property name="eventListeners">
<map>
<entry key="post-insert" >
<list>
<bean class="org.hibernate.envers.event.AuditEventListener" />
<bean class="org.hibernate.ejb.event.EJB3PostInsertEventListener" />
</list>
</entry>
<entry key="post-update">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
<entry key="post-delete">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
<entry key="pre-collection-update">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
<entry key="pre-collection-remove">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
<entry key="post-collection-recreate">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
</map>
</property>
The problem persists, and now no record is inserted in the entity tables.
Any suggestion is welcome.
Thanks.

OK.
I solved the problem.
Firstibale, it seems that with the Hibernate-core 3.5.5-Final, we don't need org.hibernate.ejb.event.EJB3PostInsertEventListener, so in our ApplicationContext-config.xml we should have just this config :
<property name="eventListeners">
<map>
<entry key="post-insert" >
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
<entry key="post-update">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
<entry key="post-delete">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
<entry key="pre-collection-update">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
<entry key="pre-collection-remove">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
<entry key="post-collection-recreate">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
</map>
</property>
Secondly, in our case our project uses two transction managers, so for the services annotated #Transactionnal we have to mention the name of the proper transaction manager used, that means that all services should be annotated as #Transactionnal(value="NAME_TX_MANAGER"). The source of this problem is that Envers doesn't work properly if we have an auto-commit (If I understood well its documentation).
I hope that may be helpful for the other visitors if the face the same difficulties.

Related

What is the Alternative to RmiRegistryFactoryBean for ConnectorServerFactoryBean as RmiRegistryFactoryBean is deprecated?

I am having an exsiting code where we are using org.springframework.remoting.rmi.RmiRegistryFactoryBean.
I am upgrading our Spring version and looks like RmiRegistryFactoryBean is deprecated in latest spring(spring-context.jar) version.
below is the code snippit I am using
<bean id="registry"
class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
<property name="port" value="{jmx.port}" />
<property name="clientSocketFactory" ref="sslRMIClientSocketFactory" />
<property name="serverSocketFactory" ref="sslRMIServerSocketFactory" />
</bean>
<bean id="serverConnector"
class="org.springframework.jmx.support.ConnectorServerFactoryBean"
depends-on="registry">
<property name="serviceUrl"
value="service:jmx:rmi://0.0.0.0:{jmx.port}/jndi/rmi://0.0.0.0:{jmx.port}/drsrmi" />
<property name="environment">
<map>
<entry key="jmx.remote.jndi.rebind" value="true"/>
<entry key="jmx.remote.tls.need.client.authentication" value="true"/>
<entry key="jmx.remote.rmi.server.socket.factory" value-ref="sslRMIServerSocketFactory"/>
<entry key="jmx.remote.rmi.client.socket.factory" value-ref="sslRMIClientSocketFactory"/>
<entry key="com.sun.jndi.rmi.factory.socket" value-ref="sslRMIClientSocketFactory"/>
</map>
</property>
</bean>
Now my ConnectorServerFactoryBean depends on registry. How can i handel this now is there any alternative for RmiRegistryFactoryBean or I can create ConnectorServerFactoryBean without registry?

Exception by getting cas attributes from DB

I deployed casv 4.2.5 in tomcat 8. The login works good. In second step I tried since 3 days to access the user attributes from database.By starting tomcat, I got the error:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'personDirectoryPrincipalResolver': Injection
of autowired dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not
autowire method: public final void
org.jasig.cas.authentication.principal.PersonDirectoryPrincipalResolver.setAttributeRepository(org.jasig.services.persondir.IPersonAttributeDao);
nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type
[org.jasig.services.persondir.IPersonAttributeDao] found for
dependency: expected at least 1 bean which qualifies as autowire
candidate for this dependency. Dependency annotations:
{#org.springframework.beans.factory.annotation.Qualifier(value=attributeRepository)}...
This is my deployerConfigContext.xml file
</util:map>
<util:map id="authenticationHandlersResolvers">
<entry key-ref="proxyAuthenticationHandler" value-ref="proxyPrincipalResolver" />
<entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" />
</util:map>
<util:list id="authenticationMetadataPopulators">
<ref bean="successfulHandlerMetaDataPopulator" />
<ref bean="rememberMeAuthenticationMetaDataPopulator" />
</util:list>
<bean id="primaryPrincipalResolver"
class="org.jasig.cas.authentication.principal.PersonDirectoryPrincipalResolver">
<property name="attributeRepository" ref="singleRowJdbcPersonAttributeDao" />
</bean>
<!-- <bean id="attributeRepository" class="org.jasig.services.persondir.support.NamedStubPersonAttributeDao"
p:backingMap-ref="attrRepoBackingMap" /> -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
p:driverClass="${database.driverClass}" p:jdbcUrl="${database.url}"
p:user="${database.user}" p:password="${database.password}"
p:initialPoolSize="${database.pool.minSize}" p:minPoolSize="${database.pool.minSize}"
p:maxPoolSize="${database.pool.maxSize}"
p:maxIdleTimeExcessConnections="${database.pool.maxIdleTime}"
p:checkoutTimeout="${database.pool.maxWait}" p:acquireIncrement="${database.pool.acquireIncrement}"
p:acquireRetryAttempts="${database.pool.acquireRetryAttempts}"
p:acquireRetryDelay="${database.pool.acquireRetryDelay}"
p:idleConnectionTestPeriod="${database.pool.idleConnectionTestPeriod}"
p:preferredTestQuery="${database.pool.connectionHealthQuery}" />
<bean id="singleRowJdbcPersonAttributeDao"
class="org.jasig.services.persondir.support.jdbc.SingleRowJdbcPersonAttributeDao">
<constructor-arg index="0" ref="dataSource" />
<constructor-arg index="1"
value="SELECT * FROM VIEWNUTZ_ROLLE WHERE {0}" />
<property name="queryAttributeMapping">
<map>
<entry key="username" value="EMAIL" />
</map>
</property>
<property name="resultAttributeMapping">
<map>
<entry key="NUZ_ID" value="nuz_id" />
<entry key="EMAIL" value="username" />
<entry key="ROLLE" value="rolle" />
</map>
</property>
</bean>
<bean id="serviceRegistryDao" class="org.jasig.cas.services.InMemoryServiceRegistryDaoImpl">
<property name="registeredServices">
<list>
<bean class="org.jasig.cas.services.RegisteredServiceImpl">
<property name="id" value="0" />
<property name="name" value="HTTPS Services" />
<property name="description" value="YOUR HTTP Service" />
<property name="serviceId" value="https://**" />
<property name="allowedAttributes">
<list>
<value>NUZ_ID</value>
<value>EMAIL</value>
<value>ROLLE</value>
</list>
</property>
</bean>
</list>
</property>
</bean>
<alias name="queryDatabaseAuthenticationHandler" alias="primaryAuthenticationHandler" />
<alias name="dataSource" alias="queryDatabaseDataSource" />
<!-- -->
<bean id="passwordEncoder"
class="de.nrw.it.portal.dias.cas.authentication.handler.Base64PasswordEncoder" />
<!-- <bean id="iPersonAttributeDao" class="org.jasig.services.persondir.IPersonAttributeDao"
/> -->
<alias name="personDirectoryPrincipalResolver" alias="primaryPrincipalResolver" />
<!-- <util:map id="attrRepoBackingMap"> <entry key="uid" value="uid" />
<entry key="eduPersonAffiliation" value="eduPersonAffiliation" /> <entry
key="groupMembership" value="groupMembership" /> <entry> <key> <value>memberOf</value>
</key> <list> <value>faculty</value> <value>staff</value> <value>org</value>
</list> </entry> </util:map> -->
<alias name="serviceThemeResolver" alias="themeResolver" />
<alias name="jsonServiceRegistryDao" alias="serviceRegistryDao" />
<alias name="defaultTicketRegistry" alias="ticketRegistry" />
<alias name="ticketGrantingTicketExpirationPolicy" alias="grantingTicketExpirationPolicy" />
<alias name="multiTimeUseOrTimeoutExpirationPolicy" alias="serviceTicketExpirationPolicy" />
<alias name="anyAuthenticationPolicy" alias="authenticationPolicy" />
<alias name="acceptAnyAuthenticationPolicyFactory" alias="authenticationPolicyFactory" />
<bean id="auditTrailManager"
class="org.jasig.inspektr.audit.support.Slf4jLoggingAuditTrailManager"
p:entrySeparator="${cas.audit.singleline.separator:|}"
p:useSingleLine="${cas.audit.singleline:false}" />
<alias name="neverThrottle" alias="authenticationThrottle" />
<util:list id="monitorsList">
<ref bean="memoryMonitor" />
<ref bean="sessionMonitor" />
</util:list>
<alias name="defaultPrincipalFactory" alias="principalFactory" />
<alias name="defaultAuthenticationTransactionManager" alias="authenticationTransactionManager" />
<alias name="defaultPrincipalElectionStrategy" alias="principalElectionStrategy" />
<alias name="tgcCipherExecutor" alias="defaultCookieCipherExecutor" />
in cas.properties file I put:
cas.principal.resolver.persondir.return.null=false
if you have ideas or examples how to configure the cas, I would be greatly thankful :)
Spring container can't find a bean of type 'org.jasig.services.persondir.IPersonAttributeDao'. Uncomment the declaration of bean 'iPersonAttributeDao' in your configuration file.

spring batch admin showing jobs as not launchable

I have a spring mvc webapp with spring batch built into it. I am having some issues getting my spring batch jobs to be launchable in the spring batch admin console. This is what I see when I go to the jobs page...
All of my jobs are coming up as launchable=false. I was wondering how I can fix this. I read some documentation about why this would be so and it said that I need to use a AutomaticJobRegistrar.
I tried this but it didn't change anything. I've put my spring batch job configuration below. Would appreciate it someone could tell me what is missing.
thanks
<beans profile="pre,prod">
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"
parent="abstractCustDbJdbcDao">
<property name="transactionManager" ref="custDbTransactionManager" />
<property name="databaseType" value="db2" />
<property name="tablePrefix" value="REPMAN.BATCH_" />
</bean>
<bean id="jobExplorer"
class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean"
parent="abstractCustDbJdbcDao" />
<bean class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
<property name="jobRegistry" ref="jobRegistry" />
</bean>
<bean id="jobLoader" class="org.springframework.batch.core.configuration.support.AutomaticJobRegistrar">
<property name="applicationContextFactories">
<bean class="org.springframework.batch.core.configuration.support.ClasspathXmlApplicationContextsFactoryBean">
<property name="resources" value="classpath*:/META-INF/spring/jobs/*.xml" />
</bean>
</property>
<property name="jobLoader">
<bean class="org.springframework.batch.core.configuration.support.DefaultJobLoader">
<property name="jobRegistry" ref="jobRegistry" />
</bean>
</property>
</bean>
<bean id="jobRegistry"
class="org.springframework.batch.core.configuration.support.MapJobRegistry" />
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobDetails">
<list>
<ref bean="dailyTranCountJobDetail" />
<ref bean="bulletinBarMsgUpdateJobDetail" />
<ref bean="updateLovCacheJobDetail" />
</list>
</property>
<property name="triggers">
<list>
<ref bean="dailyTranCountCronTrigger" />
<ref bean="bulletinBarMsgUpdateCronTrigger" />
<ref bean="updateLovCacheCronTrigger" />
</list>
</property>
</bean>
<!-- scheduling properties -->
<util:properties id="batchProps" location="classpath:batch.properties" />
<context:property-placeholder properties-ref="batchProps" />
<!-- triggers -->
<bean id="dailyTranCountCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="dailyTranCountJobDetail" />
<property name="cronExpression" value="#{batchProps['cron.dailyTranCounts']}" />
</bean>
<bean id="bulletinBarMsgUpdateCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="bulletinBarMsgUpdateJobDetail" />
<property name="cronExpression" value="#{batchProps['cron.bulletinBarUpdateMsg']}" />
</bean>
<bean id="updateLovCacheCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="updateLovCacheJobDetail" />
<property name="cronExpression" value="#{batchProps['cron.updateLovCache']}" />
</bean>
<!-- job detail -->
<bean id="dailyTranCountJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.myer.reporting.batch.JobLauncherDetails" />
<property name="group" value="quartz-batch" />
<property name="jobDataAsMap">
<map>
<entry key="jobName" value="job-daily-tran-counts" />
<entry key="jobLocator" value-ref="jobRegistry" />
<entry key="jobLauncher" value-ref="jobLauncher" />
</map>
</property>
</bean>
<bean id="bulletinBarMsgUpdateJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.myer.reporting.batch.JobLauncherDetails" />
<property name="group" value="quartz-batch" />
<property name="jobDataAsMap">
<map>
<entry key="jobName" value="job-bulletin-bar-msg-update" />
<entry key="jobLocator" value-ref="jobRegistry" />
<entry key="jobLauncher" value-ref="jobLauncher" />
</map>
</property>
</bean>
<bean id="updateLovCacheJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.myer.reporting.batch.JobLauncherDetails" />
<property name="group" value="quartz-batch" />
<property name="jobDataAsMap">
<map>
<entry key="jobName" value="job-update-lov-cache" />
<entry key="jobLocator" value-ref="jobRegistry" />
<entry key="jobLauncher" value-ref="jobLauncher" />
</map>
</property>
</bean>
</beans>
There are a few things this could be:
Where is the XML file you reference above located? It needs to be the META-INF/spring/batch/jobs directory in your WAR file (that's where Spring Batch Admin will look).
Don't configure common components in your XML file. That includes the jobLauncher, jobRepository, jobExplorer, jobLoader, or jobRegistry. That being said, I don't see an actual job defined in your XML file. The XML file needs one of those ;)
You can read more about adding your own job definitions to Spring Batch Admin: http://docs.spring.io/spring-batch-admin/reference/jobs.html#Add_your_Own_Jobs_For_Launching_in_the_UI

Read template from the database - VelocityEngine

I am storing the templates I use with velocity in the DB and I wan to configure it to read the templates from the DB.
my bean definition is:
<bean id="velocityEngineBasedOnDB" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="velocityProperties">
<map>
<entry key="resource.loader" value="ds"/>
<entry key="ds.resource.loader.class" value="org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader"/>
<entry key="ds.resource.loader.resource.table" value="tb_velocity_template"/>
<entry key="ds.resource.loader.resource.keycolumn" value="id_template"/>
<entry key="ds.resource.loader.resource.templatecolumn" value="template_definition"/>
<entry key="ds.resource.loader.resource.datasource" value-ref="dataSource"/>
</map>
</property>
</bean>
but I got java.lang.ClassCastException: 'resource.datasource' doesn't map to a String object.
So how I configure the data source as string?
Works for me
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="velocityProperties">
<map>
<entry key="resource.loader" value="ds"/>
<!--<entry key="ds.resource.loader.class" value="org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader"/>--><!--should be left out-->
<entry key="ds.resource.loader.resource.table" value="templates" />
<entry key="ds.resource.loader.resource.keycolumn" value="tid" />
<entry key="ds.resource.loader.resource.templatecolumn" value="template" />
<entry key="ds.resource.loader.resource.timestampcolumn" value="updated" />
<entry key="ds.resource.loader.instance" value-ref="dataSourceLoader" />
<entry key="ds.resource.loader.cache" value="true" />
</map>
</property>
</bean>
Data Source Loader:
<bean id="dataSourceLoader" class="org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader"> <property name="dataSource" ref="myDataSource"/><!-- myDataSource is a com.mchange.v2.c3p0.ComboPooledDataSource type--> </bean>
You have to configure another bean with id "datasource" and that will allow Spring to instantiate an instance of a class inheriting from java.sql.Datasource. It may be an OracleDataSource, for example if your database is Oracle.
you should set ds.resource.loader.instance ref a spring bean,eg:
<bean id="resourceLoader"
class="xx.common.mail.MongoDataSourceResourceLoader"
p:mongoTemplate-ref="mongoTemplate"/>
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="velocityProperties">
<map>
<entry key="resource.loader" value="ds"/>
<entry key="ds.resource.loader.instance" value-ref="resourceLoader"/>
</map>
</property>
<entry key="ds.resource.loader.resource.datasource" value-ref="dataSource"/>
value-ref doesnt work for me
change to value="datasource" and try.
It may be that value-ref support is added in higher versions (if any).
I am using Velocity 1.7
<!-- myDataSource is a com.mchange.v2.c3p0.ComboPooledDataSource type-->
<bean id="dataSourceLoader" class="org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader">
<property name="dataSource" ref="myDataSource"/>
</bean>

Wiring spring beans through custom reporting context in grails

I am using Jasper Reports for my Grails based web application and I have a ReportingContext.xml which has beans for each report like report id/name mapping with the report template (jrxml). I need to know the basic steps to configure and setup the context xmls and how to load them into my reportscontroller at application startup.
The old application was in java/j2ee which used this reporting xml. We have to develop a similar system on grails.
Most of the context contains the jrxml to report name mapping but I am not able to understand some of the beans in the context.
Here is the sample content of the reporting context.xml , for 1 report
<beans>
<!-- ========================= REPORTING SERVICE WRAPPER ========================= -->
<bean parent="baseTransactionProxy" name="myReportingService">
<property name="proxyInterfaces" value="com.pack.my.reporting.service.myReportingService"/>
<property name="transactionAttributes">
<property name="target">
<bean parent="baseServiceSupport" class="com.pack.my.reporting.service.impl.myReportingServiceImpl">
<property name="reportManager" ref="reportManager"/>
<property name="mySecurityService" ref="mySecurityService"/>
<property name="businessUnitService" ref="businessUnitService"/>
</bean>
</property>
</bean>
<bean class="com.pack.my.reporting.manager.impl.ReportManagerImpl" id="reportManager">
<property name="reportRenderers">
<map>
<entry key="JasperPrint">
<entry key="siemJasperPrint">
</map>
</property>
<property name="reportDefinitionDao" ref="reportDefinitionDao"/>
<property name="reportDao" ref="reportDao"/>
<property name="sequenceGeneratorService" ref="sequenceGeneratorService"/>
<property name="reportLocation" value="file:${my_HOME}/reports"/>
<property name="reportDefinitions">
<map>
<entry key="businessUnitRoles">
<ref local="businessUnitRoles"/>
</entry>
<entry key="businessUnitRoleUsers">
<ref local="businessUnitRoleUsers"/>
</entry>
</map>
</property>
<property name="parameterPromptCodeMap">
<bean class="org.apache.commons.collections.map.CaseInsensitiveMap">
<constructor-arg>
<map>
<entry value="1" key="businessUnit"/>
<entry value="1" key="businessUnitKey"/>
<entry value="2" key="globaluser"/>
<entry value="2" key="USERID"/>
<entry value="2" key="USER_ID"/>
<entry value="2" key="GLOBALUSERKEY"/>
<entry value="3" key="identityCertification"/>
<entry value="3" key="CERTIFICATIONID"/>
<entry value="3" key="CERTIFICATION_ID"/>
<entry value="4" key="startDate"/>
</map>
</constructor-arg>
</bean>
</property>
</bean>
<!--- Report Groups Business Unit reports Group 1 Users reports -->
<bean class="com.pack.my.reporting.domain.ReportDefinition" id="businessUnitRoles">
<property name="reportName" value="Business Unit Roles Report"/>
<property name="reportFiles">
<map>
<entry value="BusinessUnitRoles.jrxml" key="JasperPrint"/>
</map>
</property>
<property name="promptForBusinessUnit" value="true"/>
<property name="reportGroup" value="1"/>
<property name="displayName" value="report.businessUnitRoles.name"/>
<bean class="com.pack.my.reporting.domain.ReportDefinition" id="businessUnitUsers">
</bean>
</beans>
Add dependencies to grails-app/conf/BuildConfig.groovy
Copy the above file to /grails-app/conf/spring/resources.xml
Read Grails and Spring - Reference Documentation
The resources.xml is not built by default anymore, as only resources.groovy exists in the spring dir. Just copy your spring context file to resources.xml.

Resources