import java.util.Properties;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import com.demo.pojo.Products;
import com.demo.pojo.User;
public class HibernateConnection {
public static SessionFactory sessionFactory;
public static SessionFactory doHibernateConnection(){
Properties database = new Properties();
database.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
database.setProperty("hibernate.connection.username", "root");
database.setProperty("hibernate.connection.password", "");
database.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/spring");
database.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
Configuration cfg = new Configuration()
.setProperties(database)
.addPackage("com.demo.pojo")
.addAnnotatedClass(User.class)
.addAnnotatedClass(Products.class);
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties());
sessionFactory = cfg.buildSessionFactory(ssrb.build());
return sessionFactory;
}
}
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import com.demo.pojo.Products;
import com.demo.pojo.User;
public class HibernateConnection {
public static SessionFactory sessionFactory;
public static SessionFactory doHibernateConnection(){
Properties database = new Properties();
database.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
database.setProperty("hibernate.connection.username", "root");
database.setProperty("hibernate.connection.password", "");
database.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/spring");
database.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
Configuration cfg = new Configuration()
.setProperties(database)
.addPackage("com.demo.pojo")
.addAnnotatedClass(User.class)
.addAnnotatedClass(Products.class);
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties());
sessionFactory = cfg.buildSessionFactory(ssrb.build());
return sessionFactory;
}
}
--------------------------------------------------
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>HibernateStuff</groupId>
<artifactId>HibernateStuff</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Hibernate Stuff</name>
<description>Hibernate Stuff</description>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.3.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.5.4-Final</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.8.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
<version>5.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.8.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.10</version>
</dependency>
</dependencies>
</project>
No comments:
Post a Comment