gudii9
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
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
ASKER
it compiled but not inserting any values to database when i run
ASKER
i have to add all the jars as below
hibernate\example>set classpath=C:\gpSoftwares\h ibernateLi braries\*; .;
hibernate\example>javac -Xlint:deprecation *.java
StoreData.java:16: warning: [deprecation] buildSessionFactory() in Configuration has been deprecated
SessionFactory factory=cfg.buildSessionFa ctory();
^
1 warning
i am getting as above now.
please advise
hibernate\example>set classpath=C:\gpSoftwares\h
hibernate\example>javac -Xlint:deprecation *.java
StoreData.java:16: warning: [deprecation] buildSessionFactory() in Configuration has been deprecated
SessionFactory factory=cfg.buildSessionFa
^
1 warning
i am getting as above now.
please advise
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
When I run no record inserted to database table?
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
Import below in your java class and then give it a try.
import org.hibernate.service.Serv iceRegistr y;
import org.hibernate.boot.registr y.Standard ServiceReg istryBuild er;
import org.hibernate.service.Serv
import org.hibernate.boot.registr
ASKER
sure
are these from old API
why API is not backward compatible?
how to know which exmple works on which api.
import org.hibernate.service.ServiceRegistr y;
import org.hibernate.boot.registry.Standard ServiceReg istryBuild er;
are these from old API
why API is not backward compatible?
how to know which exmple works on which api.
ASKER
any other good example around this?
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");
}
}
My StoreData.java looks as above
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?