i use Hibernate for connecting to my db and i configure my database in side of my dbConnector class:
public static SessionFactory connectingHibernate(){
Properties database=new Properties();
database.setProperty("hibernate.connection.driver_class",PROPERTY_NAME_DATABASE_DRIVER);
database.setProperty("hibernate.connection.username",USERNAME);
database.setProperty("hibernate.connection.password",PASSWORD);
database.setProperty("hibernate.connection.url",url);
database.setProperty("hibernate.dialect",DIALECT);
Configuration cfg=new Configuration()
.setProperties(database)
.addPackage("androidapi.model")
.addAnnotatedClass(User.class)
.addAnnotatedClass(Product.class)
.addAnnotatedClass(PriceProduct.class)
.addAnnotatedClass(CoinPrice.class)
.addAnnotatedClass(SellPage.class)
.addAnnotatedClass(Setting.class)
.addAnnotatedClass(Message.class);
StandardServiceRegistryBuilder ssrb=new StandardServiceRegistryBuilder()
.applySettings(cfg.getProperties());
sessionFactory=cfg.buildSessionFactory(ssrb.build());
return sessionFactory;
}
when i run my application from inside of my ide my code works correctly but after making war file with maven i got this exception on methods that use my db! how can i fix this?
exception:
"error": "Internal Server Error",
"exception": "java.lang.NoSuchMethodError",
"message": "org.hibernate.cfg.Configuration.addPackage(Ljava/lang/String;)Lorg/hibernate/cfg/Configuration;",
after removeing this line: .addPackage("androidapi.model")
i got this exception:
"exception": "java.lang.NoSuchMethodError",
"message": "org.hibernate.cfg.Configuration.addAnnotatedClass(Ljava/lang/Class;)Lorg/hibernate/cfg/Configuration;",
"path": "/myinsta/admin_api/mGetAllUser"
my pom.xml Hibernate dependencies:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>LATEST</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>LATEST</version>
</dependency>
solved! read answer and its good to know that you should use compatible version of hibernate that can find here at meaven part: Maven dependency