| Author |
Hibernate Config Error
|
Gajanan Bandale
Greenhorn
Joined: May 09, 2005
Posts: 22
|
|
I am biginner for Hibernate. I create one POJO MyUsers.java, MyUsersTest.java program to run, a table myusers in MySql also one mapping file MyUsers.hbm.xml & hibernate.proprties and all placed in src folder of the application. But when i tried to run the program file MyUsersTest.java i am getting error mentioning Configuration cannot be resolved to a type Configuration cannot be resolved to a type Sessionfactory cannot be resolved to a type Session cannot be resolved to a type Please let me know why i am gettign this error. Where i am going wrong? Please help to solve the problem.
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Looks like a classpath issue. Have you got all the hibernate jars in your classpath?
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Gajanan Bandale
Greenhorn
Joined: May 09, 2005
Posts: 22
|
|
Originally posted by Paul Sturrock: Looks like a classpath issue. Have you got all the hibernate jars in your classpath?
Thanks Paul, But i added all required Jar Files in my Eclipse Build Path Here is MyUsresTest.java Code import java.util.*; import org.hibernate.*; import javax.security.auth.login.Configuration; public class MyUsersTest { public static final String Object = null; public static void main(String[]args) throws Exception { //Configuration config = new Configuration(); Object config; //((Object)config).addClass(MyUsers.class); ((Object)config).getClass(); Class SessionFactory = ((Object)config).getClass(); Session session = SessionFactory.openSession(); try{ MyUsers newUser = new MyUsers(); newUser.setID("Wipro"); newUser.setUserName("Wipro Technolgoeis"); newUser.setPassword("wipro"); newUser.setEmailAddress("wipro@tech.com"); newUser.setLastLogin(new Date()); session.save(newUser); } finally { session.flush(); session.close(); } Object object2 = SessionFactory.clone(); } } Now its give some compilation error Exception in thread "main" java.lang.Error: Unresolved compilation problems: The method openSession() is undefined for the type Class The method clone() from the type Object is not visible at MyUsersTest.main(MyUsersTest.java:17)
|
 |
mano ranjan
Ranch Hand
Joined: Jul 12, 2007
Posts: 102
|
|
Hi Use import org.hibernate.*; import org.hibernate.cfg.Configuration; these import and then try;
|
 |
Jaikiran Pai
Saloon Keeper
Joined: Jul 20, 2005
Posts: 6718
|
|
Object config; Class SessionFactory = ((Object)config).getClass(); Session session = SessionFactory.openSession();
You are calling the openSession method on a object of type Class, which is incorrect. Class does not have any such methods available on it. Have a look at Hibernate Reference to see how the SessionFactory can be configured.
|
[My Blog] [JavaRanch Journal]
|
 |
Gajanan Bandale
Greenhorn
Joined: May 09, 2005
Posts: 22
|
|
Originally posted by mano ranjan: Hi Use import org.hibernate.*; import org.hibernate.cfg.Configuration; these import and then try;
Hi I already Import the required but not any effect.
|
 |
Gajanan Bandale
Greenhorn
Joined: May 09, 2005
Posts: 22
|
|
Originally posted by Gajanan Bandale: Hi I already Import the required but not any effect.
I made some changes in my code as follows then also i find one error : import java.util.*; import org.hibernate.*; import org.hibernate.cfg.Configuration; //import javax.security.auth.login.Configuration; public class MyUsersTest { public static final String Object = null; public static void main(String[]args) throws Exception { Configuration config = new Configuration(); SessionFactory sessions = config.buildSessionFactory(); config.addClass(MyUsers.class); Session session = session.openSession(null); //Object config; //((Object)config).addClass(MyUsers.class); //((Object)config).getClass(); //Class SessionFactory = ((Object)config).getClass(); //Session session = SessionFactory.openSession(); try{ MyUsers newUser = new MyUsers(); newUser.setID("Wipro"); newUser.setUserName("Wipro Technolgoeis"); newUser.setPassword("wipro"); newUser.setEmailAddress("wipro@tech.com"); newUser.setLastLogin(new Date()); session.save(newUser); } finally { session.flush(); session.close(); } Object object2 = SessionFactory.close(); } } Then i am getting error : Exception in thread "main" java.lang.Error: Unresolved compilation problems: Cannot make a static reference to the non-static method close() from the type SessionFactory Type mismatch: cannot convert from void to Object at MyUsersTest.main(MyUsersTest.java:39)
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Its just as the error says - you are trying to assign the return value of the SessionFactory's close() method to an Object when the method's return type is void and you are calling the method as if it were a static method which it is not.
|
 |
 |
|
|
subject: Hibernate Config Error
|
|
|