Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE IF NOT EXISTS users
- (
- id INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT,
- login VARCHAR(45) NOT NULL,
- password VARCHAR(45) NOT NULL,
- full_name VARCHAR(100) NOT NULL
- );
- CREATE UNIQUE INDEX users_unique_login_idx ON users (login);
- CREATE TABLE IF NOT EXISTS user_roles
- (
- user_id INTEGER NOT NULL,
- role VARCHAR(45),
- CONSTRAINT user_roles_idx UNIQUE (user_id, role),
- FOREIGN KEY (user_id) REFERENCES users (id)
- );
- CREATE TABLE IF NOT EXISTS contacts (
- id INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT,
- user_id INTEGER NOT NULL,
- first_name VARCHAR(45) NOT NULL,
- last_name VARCHAR(45) NOT NULL,
- patronymic VARCHAR(45) NOT NULL,
- mobile_phone_number VARCHAR(15),
- home_phone_number VARCHAR(15),
- address VARCHAR(45),
- email VARCHAR(30),
- FOREIGN KEY (user_id) REFERENCES users (id)
- );
- CREATE UNIQUE INDEX contacts_unique_idx ON contacts (user_id);
- #You can use MySQL DB with next properties
- spring.jpa.database=MYSQL
- spring.datasource.url=jdbc:mysql://localhost:3306/lardi
- spring.datasource.username=root
- spring.datasource.password=2940063
- spring.datasource.driver-class-name=com.mysql.jdbc.Driver
- use.SSL=false
- <?xml version='1.0' encoding='utf-8'?>
- <!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD//EN"
- "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <!-- properties -->
- <property name="connection.url">jdbc:mysql://localhost:3306/lardi</property>
- <property name="connection.username">root</property>
- <property name="connection.password">2940063</property>
- <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
- <property name="show_sql">true</property>
- <property name="format_sql">true</property>
- <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
- <!-- mapping files -->
- <mapping class="com.model.BaseEntity"/>
- <mapping class="com.model.NamedEntity"/>
- <mapping class="com.model.Contact"/>
- <mapping class="com.model.User"/>
- <mapping class="com.model.Role"/>
- </session-factory>
- </hibernate-configuration>
- @Configuration
- @ComponentScan
- @EnableAutoConfiguration
- public class SpringBootWebApplication {
- public static void main(String[] args) {
- SpringApplication.run(SpringBootWebApplication.class, args);
- }
- }
- @Configuration
- @EnableTransactionManagement
- public class JPAConfig {
- @Bean
- public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
- LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
- em.setDataSource(dataSource());
- em.setPackagesToScan("com.model");
- JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
- em.setJpaVendorAdapter(vendorAdapter);
- em.setJpaProperties(additionalProperties());
- return em;
- }
- @Bean
- public DataSource dataSource(){
- DriverManagerDataSource dataSource = new DriverManagerDataSource();
- dataSource.setDriverClassName("com.mysql.jdbc.Driver");
- dataSource.setUrl("jdbc:mysql://localhost:3306/lardi");
- dataSource.setUsername( "root" );
- dataSource.setPassword( "2940063" );
- return dataSource;
- }
- @Bean
- public PlatformTransactionManager transactionManager(EntityManagerFactory emf){
- JpaTransactionManager transactionManager = new JpaTransactionManager();
- transactionManager.setEntityManagerFactory(emf);
- return transactionManager;
- }
- @Bean
- public PersistenceExceptionTranslationPostProcessor exceptionTranslation(){
- return new PersistenceExceptionTranslationPostProcessor();
- }
- Properties additionalProperties() {
- Properties properties = new Properties();
- properties.setProperty("hibernate.hbm2ddl.auto", "validate");
- properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
- return properties;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement