Today you are going to learn how to use hibernate in eclipse.
Learn more about hibernate by visiting here
In order to view links, you must have to reply to this thread.
How to run the example project by us in eclipse
First download the project from here
In order to view links, you must have to reply to this thread.
After creating a project In eclipse there is a possibility to add hibernate capabilities by right clicking the project so that all jar files are included.copy all jar files in that project and copy it to the downloaded project folders lib folder.These are the important jar files needed for most of our hibernate projects
ant-1.6.2
ant-antlr-1.6.2
ant-junit-1.6.2
ant-launcher-1.6.2
antlr-2.7.4
ant-swing-1.6.2
c3p0-0.8.5
cglib-full-2.0.2
cleanimports
commons-collections-2.1.1
commons-logging-1.0.4
concurrent-1.3.2
connector
dom4j-1.5.2
ehcache-1.1
hibernate3
jaas
jacc-1_0-fr
jaxen-1.1-beta-4
jboss-cache
jboss-common
jboss-jmx
jboss-remoting
jboss-system
jdbc2_0-stdext
jgroups-2.2.7
jta
junit-3.8.1
log4j-1.2.9
mysql-connector-java-3.0.16-ga-bin
oscache-2.1
proxool-0.8.3
swarmcache-1.0rc2
versioncheck
xerces-2.6.2
xml-apis
Once done Go to file->import->general->existing projects into workspace->next->select root directory where your downloaded files are->it will show hibernates2gateway ->click finish
create or using test database of mysql>use test;
create table two(id integer auto_increment primary key,bname varchar(50));
Insert some values Next in hibernate.cfg file change the dialect if you use any other database,username,password,connection url accordingly.
Quote:<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="s2s.hbm.xml"/>
</session-factory>
</hibernate-configuration>
and finally right click the project and select run as java application and select the classes name for ex "selectexample" or Directly right click the java file and run as java application it will execute the program.