Envers looks easy. Just add some hibernate properties in your persistence.xml (eventlisteners), and annotate the entities you want to audit.
I am testing this on an application using Hibernate. Here is some pom info:
org.hibernate.hibernate-entitymanager:3.4.0.GA
org.hibernate.hibernate-annotations:3.4.0.GA
org.hibernate.hibernate:3.2.6.GA
org.jboss.envers.jboss-envers:1.2.1.GA-hibernate-3.3
If I insert no annotations, my app context is loaded fine. But if I insert one, I am unable to build EntityManagerFactory.
(...)
Caused by: java.lang.NullPointerException
at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.generateInheritanceMappingData(AuditMetadataGenerator.java:305)
at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.generateFirstPass(AuditMetadataGenerator.java:353)
at org.hibernate.envers.configuration.EntitiesConfigurator.configure(EntitiesConfigurator.java:87)
at org.hibernate.envers.configuration.AuditConfiguration.(AuditConfiguration.java:86)
at org.hibernate.envers.configuration.AuditConfiguration.getFor(AuditConfiguration.java:99)
at org.hibernate.envers.event.AuditEventListener.initialize(AuditEventListener.java:260)
at org.hibernate.event.EventListeners$1.processListener(EventListeners.java:198)
at org.hibernate.event.EventListeners.processListeners(EventListeners.java:181)
at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:194)
Any help would be appreciated.
org.jboss.envers.jboss-envers:1.2.1.GA-hibernate-3.3 works with hibernate-3.3
did you try to use newer version?
Related
Im having a problem with hibernate schema generation of my postgresql databse for my webapp which is hosted in a external tomcat (8.5.20).
For this i have set the spring.jpa.hibernate.ddl-auto to create-drop in my spring boot app.
When im running the app inside my eclipse with the embedded tomcat all LocalDateTime columns are generated as
timestamp without time zone which is fine.
But when generating the the war file and deploying to a external tomcat with activated schema generation all these columns are generated as type
bytea.
I was trying to define global jndi resources (server.xml) linked in context.xml, only context.xml based jndi reosurces and with the spring.data and spring.jpa configuration im having when running in eclipse in my application.properties. But as soon as i deploy the generated war to my external tomcat these columns are generated as bytea.
I also put the postgresql-42.1.1.jar to the tomcat lib folder but also without any success.
These are my settings for my local environemt which work fine:
spring.datasource.url= jdbc:postgresql://localhost:5432/test
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
spring.jpa.hibernate.use-new-id-generator-mappings=true
spring.jpa.hibernate.ddl-auto=create-drop
This is a example of defining the tomcat jndi datasource in context.xml which generates the bytea columns:
<Resource name="jdbc/test" auth="Container"
type="javax.sql.DataSource" maxActive="20" maxIdle="5" maxWait="10000"
username="postgres" password="postgres" driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/test">
</Resource>
In this case my application properties looks like this:
spring.datasource.jndi-name=java:comp/env/jdbc/test
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
spring.jpa.hibernate.use-new-id-generator-mappings=true
spring.jpa.hibernate.ddl-auto=create-drop
Last i tried is to build and run a generated jar. Columns are again generated of type 'bytea'. So the only variant where the columns are generated as timezones is running the app inside eclipse...
Anybody an idea?
In general should NOT work. And yes, BLOB convention is used.
Java8 LocalDateTime isn't officially part of JPA 2.1
Question is WHY one config positive work? I'm almost sure, PostgreSQL has nothing t problem.
Maybe You have newer / older hibernate version? Newer Hibernate versions maybe have 'early release' ? Pure presumption, I'm in latest years Eclipselink user, and Eclipselink does NOT implement.
Generally suggested and good proven way is JPA type converter
#Converter(autoApply = true)
public class LocalDateAttributeConverter implements AttributeConverter<LocalDate, Date> {
#Override
public Date convertToDatabaseColumn(LocalDate locDate) {
return (locDate == null ? null : Date.valueOf(locDate));
}
#Override
public LocalDate convertToEntityAttribute(Date sqlDate) {
return (sqlDate == null ? null : sqlDate.toLocalDate());
}
}
EDIT: maybe You have such converter in some JAR, so automatically is forced???
EDIT2: maybe better code and theory by Adam Bien?
http://www.adam-bien.com/roller/abien/entry/new_java_8_date_and
I've been trying to use EclEmma 2.1.0.201202261248 to measure integration test coverage for DAOs. Unfortunately, any test which extends AbstractTransactionalJUnit4SpringContextTests (that is, anything which actually uses part of the spring framework) throws the following exception:
07:35:11 ERROR [main] (ASMLogger.java:72) - Exception thrown < findByFilter > exception message could not resolve property: $jacocoData of: com.asentria.asm.persistence.krp.ProductData with params :: DataFilter{SerialNum:66,KeyNum:1967,Index1:1,Index2:2,HasPendingValue:null,OrderByDesc:null,OrderByAsc:null,Class:class com.asentria.asm.filter.ProductDataFilter}
org.hibernate.QueryException: could not resolve property: $jacocoData of: com.asentria.asm.persistence.krp.ProductData
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:81)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:75)
at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1468)
...
We have an odd combination of persistence -- 1 spring-managed context which uses Hibernate directly, and one JPA-compliant context which is not managed by spring, but which also uses Hibernate for the implementation.
I know EclEmma is injecting the jacocoData field, but I have no idea how to correct the problem.
I'd be grateful for any suggestions, including ideas how how to even troubleshoot this.
Try to exclude all problem packages in Preferences
Java/Code Coverage/Excludes
I can successfully run tests with com.arjuna.* added to this setting.
enter code herewe are using c3p0 jar for databse pooling. Now from c3p0 code, the following exception is comming
Caused by: java.lang.IllegalAccessError: tried to access class com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource$1 from class com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.setUpPropertyEvents(AbstractPoolBackedDataSource.java:74)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.(AbstractPoolBackedDataSource.java:63)
at com.mchange.v2.c3p0.ComboPooledDataSource.(ComboPooledDataSource.java:109)
at com.mchange.v2.c3p0.ComboPooledDataSource.(ComboPooledDataSource.java:105)
Now in AbstractPoolBackedDataSource.java (line 74)
PropertyChangeListener l = new PropertyChangeListener()
PropertyChangeListener l = new PropertyChangeListener()
{
public void propertyChange( PropertyChangeEvent evt )
{ resetPoolManager(); }
};
So, PropertyChangeListener is the inner class here .. AbstractPoolBackedDataSource$1
PropertyChangeListener is a java class java.beans.PropertyChangeListener !!
What can be the reason ? This is only happening in linux(suse 10). In Windows it is working fine(jdk 1.6_10 and jre 1.6_20). I have tried with different jdk,jre combinations ( jdk 1.6_25 etc )
I have resolved the problem using some trial and error.
Also I found, this is not os dependable as I have suspected earlier. This is easily reproducible and looks like an potential class loading bug.( though I am not sure whether it is in equinox implementation or in java !!).
Before explaining the solution, let me describe the scenario more elaborately.
We have our code deployed in a osgi(equinox) framework. There are two bundles which uses the c3p0 jar for database pooling and one of them exports the c3p0 packages. This bundle starts before the other one.
Now, according to osgi specification, osgi class loader should maintain separate class loader instances for separate bundles. Now when the second bundle tries to load classes from the c3p0 jar, its class-loader may find (from parent delegation) that the classes are already loaded !! But they are loaded from different context, which is causing the access violation.
This is initial findings, I will try to debug with the eclipse code and may be dig more into it. After changing the bundle start order, this is resolved.
Using GeoTools with GWT, I get the following stack trace when running my app in Development Mode:
WARNING: Can't load a service for category "CRSAuthorityFactory". Cause is "ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org (...) lang.ClassCastException: class org.geotools.referencing.operation.DefaultMathTransformFactory".
sun.misc.ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.epsg.DefaultFactory could not be instantiated: java.lang.ClassCastException: class org.geotools.referencing.operation.DefaultMathTransformFactory
at sun.misc.Service.fail(Unknown Source)
at sun.misc.Service.access$200(Unknown Source)
at sun.misc.Service$LazyIterator.next(Unknown Source)
at org.geotools.factory.FactoryRegistry.register(FactoryRegistry.java:829)
at org.geotools.factory.FactoryRegistry.scanForPlugins(FactoryRegistry.java:773)
at org.geotools.factory.FactoryRegistry.scanForPluginsIfNeeded(FactoryRegistry.java:808)
at org.geotools.factory.FactoryRegistry.getUnfilteredProviders(FactoryRegistry.java:229)
at org.geotools.factory.FactoryRegistry.getServiceImplementation(FactoryRegistry.java:429)
at org.geotools.factory.FactoryRegistry.getServiceProvider(FactoryRegistry.java:364)
at org.geotools.factory.FactoryCreator.getServiceProvider(FactoryCreator.java:143)
at org.geotools.referencing.ReferencingFactoryFinder.getAuthorityFactory(ReferencingFactoryFinder.java:216)
at org.geotools.referencing.ReferencingFactoryFinder.getCRSAuthorityFactory(ReferencingFactoryFinder.java:436)
This seems to be a Jetty thing, because it works fine when I deploy to another container. Any ideas on how to fix this?
It looks like it's a problem with class-loading in Jetty. Found this GeoTools issue, and this GWT patch, both of which seem to address the problem, but neither of which seem to be getting attention at the moment. GeoMajas solves the problem with a ServletFilter to hijack Jetty's classloader: I ended up taking the same approach, which worked.
We're currently creating an app that needs ATG taglibs on SLING/OSGI, we have created a bundle with these taglibs and uploaded it, of course these taglibs call ATG classes, so we are including them in the bootdelegation, using sling.properties file.
sling.bootdelegation.simple=atg.nucleus
sling.bootdelegation.class.atg.nucleus.Nucleus=atg.appassembly, \
atg.appassembly.ant, \
atg.appassembly.progress, \
atg.appassembly.util, \
...ETC...
First we got this error:
org.apache.sling.api.scripting.ScriptEvaluationException: atg/taglib/dspjsp/ImportBeanTag
at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:163)
at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:107)
at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:226)
at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:465)
....
....
Caused by: java.lang.NoClassDefFoundError: atg/taglib/dspjsp/ImportBeanTag
at org.apache.jsp.apps.mygeometrixx.components.contenpage.center_jsp._jspx_meth_dsp_005fimportbean_005f0(center_jsp.java:177)
at org.apache.jsp.apps.mygeometrixx.components.contenpage.center_jsp._jspService(center_jsp.java:154)
at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at
So we added atg.taglib.dspjsp to the packages to be added in bootdelegation sling.properties file.
Then we got this error:
org.apache.sling.api.scripting.ScriptEvaluationException: atg.taglib.dspjsp.ImportBeanTag
at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:163)
at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:107)
at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:226)
at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:465)
...
Caused by: java.lang.ClassCastException: atg.taglib.dspjsp.ImportBeanTag
at org.apache.sling.scripting.jsp.jasper.runtime.TagHandlerPool.get(TagHandlerPool.java:125)
at org.apache.jsp.apps.mygeometrixx.components.contenpage.center_jsp._jspx_meth_dsp_005fimportbean_005f0(center_jsp.java:177)
at org.apache.jsp.apps.mygeometrixx.components.contenpage.center_jsp._jspService(center_jsp.java:154)
at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
All this is running on JBOSS.
Is there a way to avoid this class conflict that is causing the cast exception?
The class cast exception is usually a sign that that class is being made available in two different places (in your case probably via bootdelegation and maybe via a bundle that exports this class). That's what I would investigate first.
Also, to make things more explicit, I would in general advise you to not use boot delegation but instead export these packages explicitly through the system bundle. That way at least you can better debug where classes come from and how things are "wired" by the OSGi resolver.
When loading the ATG tag libraries from outside of the OSGi framework you also have to make sure to provide the JSP API from outside of the framework. By default Sling embeds the JSP API (in the JSP Scripting Bundle).
There are various ways to expose the JSP API into the framework. One is to add them to the system packages in the sling.properties file:
sling.system.packages.atg_jsp = javax.servlet.jsp;javax.servlet.jsp.el; \
javax.servlet.jsp.resources;javax.servlet.jsp.tagext;version=2.1.0