Hybernate
Hybernate
name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="hibernate.connection.password">an29@06sh</property>
<property
name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<!-- To update the table if it is set to create it will create a new table -->
<property name="hbm2ddl.auto">update</property>
<property name="hibernate.allow_update_outside_transaction">true</property>
ADD DATA:
@Entity: To create a entity
@Entity(name= “”): Give specific name to entity
@Table(name=””): To create a table
FETCH DATA:
// define the class which we want to create a table
Configuration config = new
Configuration().configure().addAnnotatedClass(Alien.class);
SessionFactory sf = config.buildSessionFactory();
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
tx.commit();
//to fetch the data we need to use the class name and the
primary key
Alien getV = session.get(Alien.class, 890);
System.out.println(getV);
// close the session
session.close();