Creating Maven Project for Hibernate
Maven is dependancy management tool . It download required jar files and add it in
project's maven dependancy folder .
when we create maven project , we do not require to download jar file and adding
it in project's build path . Maven download jar files from internet and add it in
our project automatically .
1. select file menu--> select new --> select project --> type maven in filter text
=> select maven project
2. select checkbox => create simple project
3. Sepcify group id :- [Link]
4. Sepcify artifact id (project name) :- HibernateEx
5. If you do not find src/main/java folder it means your project is NOT created
correctly
To resolve this
First Solution :- update project
Right click on project name => maven => update=>select force update checkbox
Second Solution :- use only if first solution do not work
firstly close eclipse and then go to c:/users/[your username]/.m2
delete repository folder .
[Link] depedencies in [Link] file
<dependencies>
<dependency>
<groupId>[Link]</groupId>
<artifactId>hibernate-core</artifactId>
<version>[Link]</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.30</version> <!-- 5.1.49 for mysql 5 -->
</dependency>
</dependencies>
7. copy given [Link] file and save it inside src/main/resources folder
update this file by changing password , url , driver class , username as per
your database
e.g. for MYSQL 5 in driver class's path cj. is not present , so remove it .
8. create entity class
import [Link];
import [Link];
@Entity
public class Employee
{
// name of columns and names of this class must be same
@Id
public int eid;
public String name;
public int salary;
// define setter and getter methods
}
9. save Employee class's object's contents in database table employee .
import [Link];
import [Link].*;
import [Link];
import [Link];
public class HQLSaveEx {
public static void main(String[] args) {
Session session=new
Configuration().configure().addAnnotatedClass([Link]).buildSessionFactory()
.openSession();
Employee employee=new Employee();
[Link](800);
[Link]("saurav");
[Link](800000);
Transaction tx=[Link]();
[Link](employee);
[Link]();
}