• Dear Guest, Please do NOT forget to join our JAVA JOBS (ONLY) FACEBOOK GROUP to be aware of latest JAVA openings, and you may also post any JAVA related queries/jobs.

How to run Hibernate program without Ant Tool and whether Eclipse/MyEclipse is compulsary for running Hibernate ?

#1
Hello,

I am new to hibernate.
I hv refered 1 site for hibernate intro.also hv read some programmes written in hibernate.
I want to know in depth abt hibernate.In that article I read how to run it using Ant.I want to know how to run it without Ant and whether Eclipse/MyEclipse is compulsary for running hibernate?
Reply.................
Thank you.
 
#2
Without using ANt,Eclipse,we can run the hybernate.
If u have java in your pc,that is enough to run the hybernate.

sample code

import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;
import org.hibernate.Session;
import org.hibernate.Transaction;
import pack.Student;



class StudentDB
{
public static void main(String[] args)
{
SessionFactory sessionFactory;
Session ses;
try
{
sessionFactory = new Configuration().configure().buildSessionFactory();
ses=sessionFactory.openSession();
Transaction tx=ses.beginTransaction();
Student inf=new Student();
inf.setName("Sadha");
inf.setEmail("testmail@navagate.com");
ses.save(inf);
tx.commit();
ses.flush();
ses.close();
System.out.println("Record Added");
}catch(Exception e){
e.printStackTrace();
System.out.println("The Exception is :"+e);
}



}
}


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="pack.Student" table="empdet">
<id name="id" column="ID" >
<generator class="increment"/>
</id>

<property name="name">
<column name="FIRSTNAME" />
</property>
<property name="email">
<column name="EMAIL"/>
</property>
</class>
</hibernate-mapping>

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="connection.username">root</property>
<property name="connection.password">good</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<mapping resource="Student.hbm.xml"/>
</session-factory>
</hibernate-configuration>
 
#3
Hello Mayuri,
yes u can write hibernnate program without using ANT.
U can use Eclipse ID or any other ID for better practice and run as java program.
u can run it using main method like simple java program
 
Top