Hibernate Validation and Spring 3.x - java

I am trying to use validation with Spring 3.x.
I have annotated a method field with #Valid, added <mvc:annotation-driven/> to my common.xml, and added Hibernate-Validator.jar in the lib/ dir, but I keep getting this message: "Hibernate validator not found: ignoring".
Am I missing something?
[Version:15] Hibernate Annotations 3.4.0.GA
[Environment:543] Hibernate 3.3.0.SP1
[Environment:576] hibernate.properties not found
[Environment:709] Bytecode provider name : javassist
[Environment:627] using JDK 1.4 java.sql.Timestamp handling
[Version:14] Hibernate Commons Annotations 3.1.0.GA
[AnnotationConfiguration:369] Hibernate Validator not found: ignoring

It means that Hibernate can't find the classes org.hibernate.validator.ClassValidator or org.hibernate.validator.MessageInterpolator, hinting that there's a problem with the library versions in your classpath.
I see you're using the following versions:
Hibernate Annotations 3.4.0.GA
Hibernate 3.3.0.SP1
Hibernate Commons Annotations 3.1.0.GA
And your JAR is hibernate-validator-4.0.2.GA.jar. Are you sure that all of these versions are compatible with each other?
Please try downloading the newest versions of the different Hibernate components, put them in your classpath and see if the error is still there.

At last, I found the answer at Spring ROO Issue Tracker
it is a bug in Hibernate that is
known to be corrected in Hibernate 3.5
I've this message too in my Spring project, but validation still works.

Related

Getting "http://javax.xml.XMLConstants/property/accessExternalDTD property not supported" in JBoss and using springboot

After upgrading our application to spring boot 2.6.6 in combination with JBoss 7.3 we get on every xml validation the following warnings:
2022-04-13 14:18:39,433 WARN [org.springframework.xml.validation.Jaxp15ValidatorFactory] (default task-2) http://javax.xml.XMLConstants/property/accessExternalDTD property not supported by org.apache.xerces.jaxp.validation.ValidatorImpl
2022-04-13 14:18:39,433 WARN [org.springframework.xml.validation.Jaxp15ValidatorFactory] (default task-1) http://javax.xml.XMLConstants/property/accessExternalSchema property not supported by org.apache.xerces.jaxp.validation.ValidatorImpl
Due to the intensive number of validations, the JBoss disk was filled with a log warnings resulting in a full disk.
The most obvious solution is not to use JBoss, but unfortunately that is not possible in our production environment.
The reason for the warning is that JBoss 7.3 is using an old Xerces library (2.2.12.0.SP03) which does not support the properties: accessExternalDTD and accessExternalSchema and spring-boot (2.6.6) expect support for this and log a warning when it is not supported.
Normally you should update to a newer version of the Xerces library but in the case of JBoss this is not possible because the Xerces library is packaged with JBoss.
The solution for this is to change the logging settings in JBoss to the error level for this particular logging. This can be done with the following commands:
${JBOSS_HOME}/bin/jboss-cli.sh --connect controller=localhost:9990 --user=<admin user> --password=<password> --command="/subsystem=logging/logger=org.springframework.xml.validation.Jaxp15ValidatorFactory:add"
${JBOSS_HOME}/bin/jboss-cli.sh --connect controller=localhost:9990 --user=<admin user> --password=<password> --command="/subsystem=logging/logger=org.springframework.xml.validation.Jaxp15ValidatorFactory:write-attribute(name=level, value=ERROR)"
The provided implementation of the ValidatorFactory doesn't support the mentioned property.
As it's mentioned in the answer of #Gerard, JBoss org.apache.xerces dependency provides its implementation.
You can configure your program to use the implementation that supports or ignores the mentioned property.
I elaborated on the details in another similar answer.

Multiple annotations found at this line: Factory bean not Found

I am building a Spring project in Spring Tool Suite(3.6.4.RELEASE).
I am trying to upgrade spring framework version from 4.0.3.RELEASE to 4.2.7.RELEASE using maven.
Before upgradation there was no error and everything running smoothly. Now project is compiling and running without error but login page is not showing and also I am getting error in my spring security configuration xml.
Error in spring-security.xml:
Showing following error on STS hovering:
Multiple annotations found at this line:
- Factory bean 'org.springframework.security.config.http.FilterInvocationSecurityMetadataSourceParser
$DefaultWebSecurityExpressionHandlerBeanFactory' not found [config set: mcare-dashboard-web/web-context]
- Factory bean 'org.springframework.security.config.http.HttpConfigurationBuilder
$SecurityContextHolderAwareRequestFilterBeanFactory' not found [config set: mcare-dashboard-web/web-context]
Project Hierarchy:
My pom.xml was like following:
Then I just changed the version number like this:
After that spring-security.xml was showing the error.
Can anybody explain why is this happening?
You state that you are upgrading Spring from version 4.0.3.RELEASE to 4.2.7.RELEASE. However effectively you are upgrading both Spring and Spring Security. This due to having a single version property, named org.springframework-version, to manage both the version of the Spring and Spring Security dependencies.
So changing org.springframework-version to 4.2.7.RELEASE effectively upgrades Spring Security as well.
To fix this you want to have two distinct version properties one for Spring and another for Spring Security. You can than upgrade only Spring or Spring Security.

unitils-orm-hibernate not working with Hibernate 5

I'm using unitils for hibernate orm testing. I took the hibernate version 5.0.10-Final and the latest unitils version 3.4.3.
I'm always getting the following error: "org.unitils.core.UnitilsException: An exception occured during the loading of core module hibernate with module class name org.unitils.orm.hibernate.HibernateModule -> Caused by: org.unitils.core.UnitilsException: Could not load class with name org.hibernate.cfg.AnnotationConfiguration"
When I look into the code I can see (in older version of Hibernate 4) that the AnnotationConfiguration is deprecated and will be replaced in Hibernate 5. Apparently the unitils still expects the class to be there as the property 'HibernateModule.configuration.implClassName' still points towards this class.
Do I need an other configuration? Or an other version?
You just need to add to unitils configuration next line:
HibernateModule.configuration.implClassName=org.hibernate.cfg.Configuration

How to initialize annotation configuration instance in Hibernate 4?

I am using hibernate-release-4.2.4.Final version and tried using annotations instead of the hbm.xml file. But while running, it always throws an-annotation-configuration-instance-is-required-to-use-error.
When I tried importing org.hibernate.AnnotationConfiguration it showed the class was deprecated.
Then I tried copying Annotation configuration class file from the hibernate-annotation.jar and used and it in the hibernate3.jar and it worked fine.
My question is how to initialize a annotation configuration instance in the newer version of Hibernate release?
In Hibernate 4 you should not use AnnotationConfiguration anymore, use Configuration instead.
Use HibernateUtils or other session factory builder to build the session factory.
An example of such utility you could find here.

Hibernate/JPA inheritance issue on weblogic

Im getting a weird error when running my spring2.5.6,jpa(hibernate3.4) webapp in weblogic 10.3
[ERROR] Javassist Enhancement failed: com.xxx.domain.model.Scheme
java.lang.NoSuchMethodError: pcGetManagedFieldCount
at com.xxx.domain.model.Fund.<clinit>(Fund.java)
at sun.misc.Unsafe.ensureClassInitialized(Native Method)
at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAc
cessorFactory.java:25)
The com.xxx.domain.model.Scheme class is a mapped subclass entity of the abstract fund entity on a single_table inheritance hierarchy, and I'm getting this error for all entities on the hierarchy. I'm using both annotated classes and xml metadata to define the mappings for my persistence classes.
I only get this error when the app is deployed to weblogic, so everything runs fine using junit. I have tried upgrading to the latest version on javaassit.jar.
Problem Looks to me like an issue with classloading order, but I cant figure it out.
PS. As suggested by bea I have added the following to the weblogic.xml
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
Anyone got any ideas, other config tips, or directions I should take my investigation?
I had the same problem.
My entities extended a class (#MappedSuperClass) which lived inside a jar dependency. I had to move that class from the jar into my project. Only then it would work and deployed fine.
Also another way to solve this is to specify your entities explicitly in the persistence.xml
I'm sorry, I only have WebLogic 10.0 on my machine, and it doesn't have any javassist JARs in the distro. Looks like javassist was only added in 10.3 for AOP byte code generation.
It might be worth a try to remove the javassist JAR from your WebLogic deployment and use the version that it supports. Take the "prefer-web-inf-classes" tag out of your web.xml and see if it can work with the version that WebLogic prefers.
Can you post the code for the entity class and, if you're not using annotations, the segment of your hbm mapping file?
Your classpath hunch may be right on. In your weblogic-application.xml, try this
<prefer-application-packages>
<package-name>antlr.*</package-name>
<package-name>org.antlr.*</package-name>
</prefer-application-packages>
If you have any more log output, please post that as well.
I just lost a couple of days on this myself. The problem for me was that I 2 separate data-services modules in my app. I'm thinking 10.3 has some trouble with that. I'm not sure of the solution, but a work around for me was to combine both of my data-services modules into just one.
BEA seems to be aware of this issue. Hopefully the URL below will help. Reference CR370788.
http://edocs.bea.com/wls/docs103/issues/known_resolved.html

Categories

Resources