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.
Related
I Can see the following warning with #ConfigurationProperties Annotation
When using #ConfigurationProperties it is recommended to add 'spring-boot-configuration-processor' to your classpath to generate configuration metadata
Everything working fine. What it meant for?
If you add an optional dependency to the “spring-boot-configuration-processor”, your module will hold a meta-data file that is generated at compile time with details about your properties. IDEs can then pick that up to show you content assist/auto-completion. STS, Intellij IDEA and Netbeans have such support .
It is an annotation processor that generates metadata about classes in your application that are annotated with #ConfigurationProperties.
More info here: http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#configuration-metadata
https://docs.spring.io/spring-boot/docs/2.1.1.RELEASE/reference/htmlsingle/#configuration-metadata-annotation-processor
I have a plugin-based Eclipse app where I put my persistent data in X plugin, and the hibernate-database service in Y plugin.
The persistent classes are in X, and the HibernateUtil, Dao, all the hibernate-related jars and the hbm.xml mapping files for the persistent classes are in Y.
When I run the app, I see lots of exceptions like:
java.lang.RuntimeException
javassist.CannotCompileException
java.lang.ClassNotFoundException
org.hibernate.HibernateException
All of them end with "java.lang.NoClassDefFoundError: org/hibernate/proxy/HibernateProxy"
If I work with a database on my localhost, these exceptions don't affect my app.
But when I try to connect to a remote database, my nested HQL queries don't work. I'm guessing that this has something to do with the proxies.
Is there a way to get rid of this problem without merging X and Y plugins into a single plugin?
The problem isn't most probably due to the loading mechanism of eclipse plugins. There's a fix for that - the buddy loading.
In the MANIFEST.MF file of the Hibernate plugin (which NEEDS the buddy loading), such as org.hibernate.eclipse, add a line:
Eclipse-BuddyPolicy:registered
and in the MANIFEST.MF file of your plugin project or RCP project, add the line:
Eclipse-RegisterBuddy:org.hibernate.eclipse
This should resolve the issue.
Here's a blog post around this problem:
http://hwellmann.blogspot.de/2008/11/hibernate-and-osgi-pragmatic-solution.html
Hibernate supporting libraries were missed in your remote deployment.
create a lib folder under WEB-INF and copy all the supporting jar files to this lib folder.
This solves the problem:
In X plugin,
Eclipse-BuddyPolicy: registered
In Y plugin,
Require-Bundle: (x plugin id)
Eclipse-RegisterBuddy: (x plugin id)
At its root, this is a classic OSGi ClassLoader issue. The solution depends on the version of Hibernate you are using.
Hibernate 4.X
You must set the ProxyFactory classLoaderProvider to provide a class loader that includes
Your entity classes
Hibernate Proxy (org.hibernate.proxy)
Javassist proxy (javassist.util.proxy)
Hibernate 5.X
Hibernate now uses the classloader of the entity class in the proxy factory. You must include Hibernate proxy (org.hibernate.proxy) and Javassist (javassist.util.proxy) in the Import-Package section of the OSGi Manifest of the bundle(s) that contains the entity classes 3, which may be different from the bundle that creates the EntityManagerFactory.
I had this exception running an Arquillian Test.
In my case i forgot to add persistence.xml to the archive:
archive.addAsResource("META-INF/persistence.xml", "META-INF/persistence.xml");
I'm having an issue with a PropertiesFactoryBean not being resulved to a Properties object in spring. Instead I get the following error:
org.springframework.beans.factory.BeanNotOfRequredTypeException: Bean named 'authProperties' must be of type [java.util.Properties], but was actually of type [org.springframework.beans.factory.config.PropertiesFactoryBean]
at org.springFramework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:367)
at org.springFrameowkr.beans.factory.support.AbstractBeanFactory.etBean(AbstractBeanFactory.java:198]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1121
at *our code here*
This code was written by others who have used it reliably for some time, so the issue is likely configuration issue rather then bad code. However, the failure occurs on the return line of this method:
private static Properties getPropsFromContext(String context) {
try(AbstractApplicationContext ctx = new ClassPathXmlApplicationContext(context)){
return ctx.getBeans("authProperties", Properties.class));
}
}
The relevant lines of the XML file are:
<bean id="authProperties" class="org.springFramework.beans.factory.config.PropertiesFactoryBean">
<property name="location" value="classpath:props/auth.properties" />
</bean>
Ultimately the code is being called from within tomcat. We are using our own RealmBase class for the tomcat Relm, which calls this code. The jar containing our RealmBase class is in the tomcat/lib directory.
What should happen is that spring should recognize that PropertiesFactoryBean implements the FactoryBean interface and it should call getObject of the PropertiesFactoryBean as part of the getObjectForBeanInstance called by doGetBean method, which would return the Properties object. However, for some reason this is not happening, and I'm getting the PropertiesFactoryBean object back instead of the Property being returned. I've even looked through the code to verify this.
Our unit tests of this method run fine, which once again suggests the failure is not with the code, but sometime after it gets compiled, likely a configuration issue with tomcat. As far as I can tell there are no duplicate spring jars in the tomcat classpath or other obvious naming collisions.
I'm using Tomcat6. Our spring jars are mostly 3.2.9, a few 3.1.0, but I think the relevant jars are all 3.2.9
Why would it fail to generate the Property value correctly?
I ultimately discovered I was running an outdated version of the realm jar. When I installed the new Realm things worked correctly. I assume my issue was that the old Realm was compiled to a different version of spring.
I have trouble getting #Value annotations working with a Spring bean in a Grails 2.3.4 app.
I have a separate jar as a Grails dependency. The jar has annotated beans:
#Named
public class Bean {
#Value("${client.environment}")
private String environment;
....
}
I have setup the property in Config.groovy.
...
client.environment = "DEV"
...
When I run Grails in IntelliJ IDEA the property works and the #Value annotated variable is populated automatically. But when I deploy the war to a standalone Jetty instance the same property has not been initialized and its value is instead "${client.environment}".
I have tried for hours to check all production and development settings so they don't change anything. I've also tried multiple solutions to load properties in Grails and even tried to setup a propertyPlaceholderConfigurer in resources.groovy but nothing helps.
The #Value annotation from Spring needs single quotes in order to work (Tested on Grails 4):
import org.springframework.beans.factory.annotation.Value;
public class Bean {
#Value('${client.environment}')
String environment;
...
}
So I got the bean working as inteded by following these instructions. First I read the property from the property file and explicitly set it to the bean variable using the last method in the following URL (using beans in Config.groovy)
http://softnoise.wordpress.com/2013/07/29/grails-injecting-config-parameters/
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.