• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Hibernate Config Error

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like a classpath issue. Have you got all the hibernate jars in your classpath?
 
Gajanan Bandale
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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)
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Use
import org.hibernate.*;
import org.hibernate.cfg.Configuration;
these import and then try;
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Gajanan Bandale
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Something must be done about this. Let's start by reading this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!