Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

hibernate example issues from command prompt

Hi,

When i tried below simple hibernate example from eclipse it worked fine.(i just downloaded source code from link and imported general project and then archive file)

http://www.javatpoint.com/example-to-create-hibernate-application-in-eclipse-ide



When i tried from command prompt i am getting below error while compiling
http://www.javatpoint.com/steps-to-create-first-hibernate-application

hibernate\example>javac *.java
Note: StoreData.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

i tried as below

hibernate\example>javac -Xlint:unchecked StoreData.java
Note: StoreData.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.


still not working how to fix it/

please advise
hibernate1.png
hibernate2.png
Avatar of mccarl
mccarl
Flag of Australia image

Ahhh, where to start....

Firstly, what you have posted is about a compiler WARNING not an error, so it should have still gone on to compile ok. If not, then there is some other error that is stopping it (more likely scenario) and if you want help with that, you would need to post the errors (not the warnings)

As for the warning itself, it told you to recompile with -Xlint:deprecation so why did you compile with something totally different (-Xlint:unchecked) and expect it to make any difference?
Avatar of gudii9

ASKER

it compiled but not inserting any values to database when i run
Avatar of gudii9

ASKER

i have to add all the jars as below
hibernate\example>set classpath=C:\gpSoftwares\hibernateLibraries\*;.;


hibernate\example>javac -Xlint:deprecation  *.java
StoreData.java:16: warning: [deprecation] buildSessionFactory() in Configuration has been deprecated
    SessionFactory factory=cfg.buildSessionFactory();
                              ^
1 warning




i am getting as above now.

please advise
ASKER CERTIFIED SOLUTION
Avatar of Am P
Am P
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

ASKER

When I run no record inserted to database table?
Avatar of gudii9

ASKER

getting below errors now

javatpointHibernate>javac *.java
StoreData.java:16: error: cannot find symbol
            ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();
            ^
  symbol:   class ServiceRegistry
  location: class StoreData
StoreData.java:16: error: cannot find symbol
            ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();
                                                  ^
  symbol:   class ServiceRegistryBuilder
  location: class StoreData
StoreData.java:17: error: cannot find symbol
    SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
                                    ^
  symbol:   variable configuration
  location: class StoreData
StoreData.java:20: error: cannot find symbol
        Session session=factory.openSession();
                        ^
  symbol:   variable factory
  location: class StoreData
4 errors

Open in new window

Import below in your java class and then give it a try.


import org.hibernate.service.ServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
Avatar of gudii9

ASKER

sure

import org.hibernate.service.ServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;

are these from old API

why API is not backward compatible?
how to know which exmple works on which api.
Avatar of gudii9

ASKER

any other good example around this?
Avatar of gudii9

ASKER

gpCode\javatpointHibernate>javac -Xlint:deprecation  *.java
StoreData.java:16: warning: [deprecation] buildSessionFactory() in Configuration has been deprecated
    SessionFactory factory=cfg.buildSessionFactory();
                              ^
1 warning

when i compile with -Xlint:deprecation  getting above error
//package com.javatpoint.mypackage;  
  
import org.hibernate.Session;  
import org.hibernate.SessionFactory;  
import org.hibernate.Transaction;  
import org.hibernate.cfg.Configuration;  
  
public class StoreData {  
public static void main(String[] args) {  
      
    //creating configuration object  
    Configuration cfg=new Configuration();  
    cfg.configure("hibernate.cfg.xml");//populates the data of the configuration file  
      
    //creating seession factory object  
    SessionFactory factory=cfg.buildSessionFactory();  
      
    //creating session object  
    Session session=factory.openSession();  
      
    //creating transaction object  
    Transaction t=session.beginTransaction();  
          
    Employee e1=new Employee();  
    e1.setId(115);  
    e1.setFirstName("sonoo");  
    e1.setLastName("jaiswal");  
      
    session.persist(e1);//persisting the object  
      
    t.commit();//transaction is commited  
    session.close();  
      
    System.out.println("successfully saved");  
      
}  
}  

Open in new window


My StoreData.java looks as above