In refrence to this. I am making an hibernate demo in which I want to map all the POJO classes dynamically. I found the above given reference and tried to scan my classes from the package mapping only. But it is giving some errors like:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Predicate
at com.telemune.util.StringUtil.getSessionFactory(StringUtil.java:44)
at com.telemune.generator.TableDescriber.describeTable(TableDescriber.java:33)
at com.telemune.generator.PojoGenerator.main(PojoGenerator.java:169)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Predicate
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 3 more
when I added com.google.common_1.0.0.201004262004.jar I got this:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.copyOf(Ljava/util/Collection;)Lcom/google/common/collect/ImmutableSet;
at org.reflections.Reflections.getTypesAnnotatedWith(Reflections.java:358)
at com.telemune.util.StringUtil.getSessionFactory(StringUtil.java:46)
at com.telemune.generator.TableDescriber.describeTable(TableDescriber.java:33)
at com.telemune.generator.PojoGenerator.main(PojoGenerator.java:169)
I am not able to ask or comment there that's why I am asking it here specially to @MartinAubele, @Jonathan, @SergeyBrunov, @ArthurRonald. Please give an example or something by which I can use google-reflections to scan my package.
Please Note: I don't want to use Spring. So please don't suggest about that. Thanks in Advance.
some code Sample:
SessionFactory sfactory = null;
ServiceRegistry serviceRegistry=null;
Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
Reflections reflections = new Reflections(PojoGenerator.pkgName);
Set<Class<?>> classes = reflections.getTypesAnnotatedWith(javax.persistence.Entity.class);
for(Class<?> clazz : classes)
{
configuration.addAnnotatedClass(clazz);
}
serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
sfactory = configuration.buildSessionFactory();
and another problem is : configuration.buildSessionFactory(); is not allowing me to use configuration.buildSessionFactory(serviceRegistry);