- Hibernate Diagram.pdf
- Native hibernate bootstrapping
- CRUD operations
- Relationships (One2One | One2Many | Many2Many)
- Javafx-fxml with Hibernate
- Query Languages (HQL Vs. SQL)
- Install Git on your computer: https://git-scm.com/downloads
- Then on your terminal. Run 👇
git clone https://github.com/DanujaV/hibernate-and-jpa-cmjd100.git
//import lk.ijse.query.entity.Customer;
import org.hibernate.SessionFactory;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
public class HibernateUtil { //Session Factory
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder()
// .configure("/hibernate.cfg.xml")
.loadProperties("/application.properties")
.build();
Metadata metadata = new MetadataSources(standardRegistry)
// .addAnnotatedClass(Customer.class)
.getMetadataBuilder()
.applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE)
.build();
SessionFactory sessionFactory = metadata.getSessionFactoryBuilder()
.build();
return sessionFactory;
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
- XML Configuration
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/nh_cmjd100?createDatabaseIfNotExist=true</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>-->
</session-factory>
</hibernate-configuration>
OR
- Resource Bundle Configuration
#key=value pairing
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class=com.mysql.cj.jdbc.Driver
hibernate.connection.url=jdbc:mysql://localhost:3306/cmjd100_thogakade?createDatabaseIfNotExist=true
hibernate.connection.username=root
hibernate.connection.password=password
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.hbm2ddl.auto=update
Copyright 2023 CMJD. All Rights Reserved.