Код: Выделить всё
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.mortal
HibernateDemo
0.0.1-SNAPSHOT
jar
HibernateDemo
http://maven.apache.org
UTF-8
org.hibernate
hibernate-core
5.4.27.Final
javax.xml.bind
jaxb-api
2.3.1
com.mysql
mysql-connector-j
8.3.0
javax.activation
javax.activation-api
1.2.0
javax.xml.bind
jaxb-api
2.3.1
org.glassfish.jaxb
jaxb-core
2.3.0.1
org.glassfish.jaxb
jaxb-runtime
2.3.3
junit
junit
3.8.1
test
Код: Выделить всё
com.mysql.cj.jdbc.Driver
jdbc:mysql://localhost:3306/myhiber
root
root
org.hibernate.dialect.MySQL8Dialect
update
true
Код: Выделить всё
package com.mortal.hibernate;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
public class Student {
@Id
private int id;
private String name;
private String city;
public Student(int id, String name, String city) {
super();
this.id = id;
this.name = name;
this.city = city;
}
public Student() {
super();
// TODO Auto-generated constructor stub
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
@Override
public String toString() {
return "Student [id=" + id + ", name=" + name + ", city=" + city + "]";
}
}
Код: Выделить всё
package com.mortal.hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class App {
public static void main(String[] args) {
System.out.println("Project Started!!!!!!!!");
SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
System.out.println(factory);
// Creating student object...
Student st = new Student(101, "John Cena", "New York");
System.out.println(st);
Session session = factory.openSession();
session.beginTransaction();
session.save(st);
session.getTransaction().commit();
session.close();
factory.close();
}
}
-с использованием eclipse IDE
-MySQL 8.0.3
-пробовано с некоторыми версиями h5 и h4
Подробнее здесь: https://stackoverflow.com/questions/787 ... entity-hib