CREATE TABLE `employee` (
`id` BIGINT(10) NOT NULL AUTO_INCREMENT,
`firstname` VARCHAR(50) NULL DEFAULT NULL,
`lastname` VARCHAR(50) NULL DEFAULT NULL,
`birth_date` DATE NOT NULL,
`cell_phone` VARCHAR(15) NOT NULL,
PRIMARY KEY (`id`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
AUTO_INCREMENT=606
Code language: SQL (Structured Query Language) (sql)
<?xml version="1.0" encoding="UTF-8"?><project>
<modelVersion>4.0.0</modelVersion>
<groupId>HibernateCache</groupId>
<artifactId>HibernateCache</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description></description>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>ejb3-persistence</artifactId>
<version>1.0.1.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.3.1.GA</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.10</version>
</dependency>
</dependencies>
</project>
Code language: HTML, XML (xml)
Once we update the Hibernate dependency, run following command in your project folder to update classpath in eclipse to that errors are removed. Code language: HTML, XML (xml)mvn eclipse:eclipse
package net.viralpatel.hibernate;
import java.sql.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="EMPLOYEE")
public class Employee {
@Id
@GeneratedValue
private Long id;
@Column(name="firstname")
private String firstname;
@Column(name="lastname")
private String lastname;
@Column(name="birth_date")
private Date birthDate;
@Column(name="cell_phone")
private String cellphone;
public Employee() {
}
public Employee(String firstname, String lastname, Date birthdate, String phone) {
this.firstname = firstname;
this.lastname = lastname;
this.birthDate = birthdate;
this.cellphone = phone;
}
// Getter and Setter methods
}
Code language: Java (java)
return new Configuration()
.configure()
.buildSessionFactory();
Code language: Java (java)
Change this line and use AnnotationConfiguration instead of Configuration(). Replace this line with below code. // import org.hibernate.cfg.AnnotationConfiguration;
return new AnnotationConfiguration()
.configure()
.buildSessionFactory();
Code language: Java (java)
<mapping resource="net/viralpatel/hibernate/Employee.hbm.xml"/>
Code language: HTML, XML (xml)
Replace above line with following: <mapping class="net.viralpatel.hibernate.Employee"/>
Code language: HTML, XML (xml)
******* READ *******
Total Employees: 200
******* WRITE *******
201 Jack Bauer
******* UPDATE *******
Name Before Update:Paula
Name Aftere Update:James
******* DELETE *******
Object:null
Code language: Java (java)
Java URL Encoder/Decoder Example - In this tutorial we will see how to URL encode/decode…
Show Multiple Examples in OpenAPI - OpenAPI (aka Swagger) Specifications has become a defecto standard…
Local WordPress using Docker - Running a local WordPress development environment is crucial for testing…
1. JWT Token Overview JSON Web Token (JWT) is an open standard defines a compact…
GraphQL Subscription provides a great way of building real-time API. In this tutorial we will…
1. Overview Spring Boot Webflux DynamoDB Integration tests - In this tutorial we will see…
View Comments
Awesome Tutorial.
In pom.xml, currently, the annotations, JPA etc.. are part of hibernate-core dependency.
Please do update Dependencies in pom.xml to:
(Remove extra ""). Some issues with posting comment here
<>
<>mysql<>
<>mysql-connector-java<>
<>5.1.18<>
<>
<>
<>org.hibernate<>
<>hibernate-core<>
<>4.0.0.Final<>
<>
<>
<>junit<>
<>junit<>
<>3.8.1<>
<>test<>
<>
thanks VP...thanks for a wonderful food .
Thanks
Zaks
How to connect with oracle.........
how to connect with oracle 10g
Hi Sam, To connect with Oracle database use following settings in hibernate configuration file.
[code language="xml"]
<property name="hibernate.connection.driver_class">
oracle.jdbc.OracleDriver
</property>
<property name="hibernate.connection.url">
jdbc:Oracle:thin:@127.0.0.1:8080/employee
</property>
<property name="hibernate.connection.username">
MyUsername
</property>
<property name="hibernate.connection.password">
Somepassword
</property>
<property name="dialect">
org.hibernate.dialect.OracleDialect
</property>
[/code]
Im not able to work with Hibernate annotations when i tried to run the project im getting Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
Exception in thread "main" java.lang.ExceptionInInitializerError error
Can anyone share the JARS for Hibernates along with annotations hibernate official site is blocked for us in office
Source download link doesn't work.
Hi Swen, Download link is working. Please check if download is not blocked in your browser.
This is very good tutorial for beginner but only problem at adding supported jar file. otherwise will run this example by a new comer. Thank u bhaava.....
Hi viral...
Thanks for your wonderful blog.
I am trying to integrate hibernate with JSF. Do you any example for this. I tried to google for this but did not find any useful example.
Awesome tutorial, I looked for Hibernate project with maven on Youtube, google and finally got your blog.
I worked perfectly.
Thank you so much!!!!!!