Maven Steps Updated
Maven Steps Updated
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
5. If you do not find src/main/java folder it means your project is NOT created
correctly
To resolve this
Right click on project name => maven => update=>select force update checkbox
<dependencies>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.4.0.Final</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 hibernate.cfg.xml 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 .
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
@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;
import java.util.List;
import org.hibernate.*;
import org.hibernate.cfg.Configuration;
import com.tka.entity.Employee;
Session session=new
Configuration().configure().addAnnotatedClass(Employee.class).buildSessionFactory()
.openSession();
employee.setEid(800);
employee.setName("saurav");
employee.setSalary(800000);
Transaction tx=session.beginTransaction();
session.save(employee);
tx.commit();
}