Reputation: 544
I have been embarking on a project using Hibernate where I want to retrieve data. However, when I try configuring the AnnotationConfiguration
like the one below,
try {
factory = new AnnotationConfiguration().
configure().
//addPackage("com.xyz") //add package if used.
addAnnotatedClass(AbtDebtbbyCAN.class).
buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Failed to create sessionFactory object." + ex);
throw new ExceptionInInitializerError(ex);
}
I'm getting error like :
Cannot resolve symbol 'AnnotationConfiguration'
May I know how to resolve the error? I believe the mistake lies in the Gradle configuration for Hibernate. This is how I've configured it.
Build.Gradle
compile group: 'org.hibernate', name: 'hibernate-gradle-plugin', version: '5.4.22.Final'
Note: AbtDebtbyCAN
is an entity class
Upvotes: 0
Views: 1178
Reputation: 544
I've found out the reason why it gave me an error. Basically, “org.hibernate.cfg.AnnotationConfiguration”
is deprecated after the release of Hibernate 3.6
. As a result, all its functionality has been moved to “org.hibernate.cfg.Configuration“
and hence the code needs to be amended like this:
try {
factory = new Configuration().
configure().
//addPackage("com.xyz") //add package if used.
addAnnotatedClass(AbtDebtbbyCAN.class).
buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Failed to create sessionFactory object." + ex);
throw new ExceptionInInitializerError(ex);
}
Hence, in this way, the program can be executed. So, to top it all up, it's got nothing to with Gradle
, it's got to do with the compatibility of the configuration. Hope this answers the question.
Upvotes: 2