I am creating session factory by reading properties file which is outside from by project.
My Properties file is as follows,
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.username=root
hibernate.connection.password=root
hibernate.connection.url=jdbc:mysql://localhost:3306/hi5
hibernate.dialect=org.hibernate.dialect.MySQLDialect
entity=CmtFreeformpages,CmtNewsTicker
I am creating Sessionfactory by reading the properties file as follows,
properties.load(new FileReader(new File(global.constants.GlobalConstants.parentDirectory + File.separator + global.constants.GlobalConstants.propertiesFile)));
Configuration configuration = new Configuration().setProperties(properties);
Set<Object> setOfProperties = properties.keySet();
for(Object propertyObject : setOfProperties){
if (propertyObject != null) {
String propName = propertyObject.toString();
if(propName.equalsIgnoreCase("entity")){
String value = properties.getProperty(propName);
Object[] entities = value.split(",");
for(int i=0;i<entities.length;i++){
configuration.addAnnotatedClass(entities[i]);
}
sessionFactory = configuration.buildSessionFactory();
but configuration.addAnnotatedClass method is not accepting the string.So how to add the annotated classes to the configuration ?
Thanks
Since
addAnnotatedClass()accepts aClass, you need to getClasses for the given class names usingClass.forName():Note that
Class.forName()expects fully qualified class names, i.e. with package names included.