JAVA-10081: Removed unused files and updated pom.xml

This commit is contained in:
anuragkumawat 2022-02-23 19:54:43 +05:30
parent d003088364
commit bb7b461a49
46 changed files with 74 additions and 303 deletions

View File

@ -1,8 +0,0 @@
package com.baeldung.persistence.manytomany.dao;
import com.baeldung.hibernate.manytomany.model.Employee;
import com.baeldung.persistence.dao.common.IOperations;
public interface IEmployeeDao extends IOperations<Employee>{
}

View File

@ -1,8 +0,0 @@
package com.baeldung.persistence.manytomany.dao;
import com.baeldung.hibernate.manytomany.model.Project;
import com.baeldung.persistence.dao.common.IOperations;
public interface IProjectDao extends IOperations<Project>{
}

View File

@ -1,75 +0,0 @@
package com.baeldung.spring;
import com.google.common.base.Preconditions;
import org.apache.tomcat.dbcp.dbcp2.BasicDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
import org.springframework.orm.hibernate5.HibernateTransactionManager;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;
import java.util.Properties;
@Configuration
@EnableTransactionManagement
@PropertySource({ "classpath:persistence-h2.properties" })
@ComponentScan({ "com.baeldung.persistence" })
public class PersistenceConfig {
@Autowired
private Environment env;
@Bean
public LocalSessionFactoryBean sessionFactory() {
final LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(dataSource());
sessionFactory.setPackagesToScan(new String[] { "com.baeldung.persistence.model" });
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
@Bean
public DataSource dataSource() {
final BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName")));
dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url")));
dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user")));
dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass")));
return dataSource;
}
@Bean
public PlatformTransactionManager hibernateTransactionManager() {
final HibernateTransactionManager transactionManager = new HibernateTransactionManager();
transactionManager.setSessionFactory(sessionFactory().getObject());
return transactionManager;
}
@Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
private final Properties hibernateProperties() {
final Properties hibernateProperties = new Properties();
hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));
hibernateProperties.setProperty("hibernate.show_sql", "false");
// Envers properties
hibernateProperties.setProperty("org.hibernate.envers.audit_table_suffix", env.getProperty("envers.audit_table_suffix"));
return hibernateProperties;
}
}

View File

@ -1,31 +0,0 @@
insert into item (item_id, item_name, item_desc, item_price)
values(1,'item One', 'test 1', 35.12);
insert into item (item_id, item_name, item_desc, item_price)
values(2,'Pogo stick', 'Pogo stick', 466.12);
insert into item (item_id, item_name, item_desc, item_price)
values(3,'Raft', 'Raft', 345.12);
insert into item (item_id, item_name, item_desc, item_price)
values(4,'Skate Board', 'Skating', 135.71);
insert into item (item_id, item_name, item_desc, item_price)
values(5,'Umbrella', 'Umbrella for Rain', 619.25);
insert into item (item_id, item_name, item_desc, item_price)
values(6,'Glue', 'Glue for home', 432.73);
insert into item (item_id, item_name, item_desc, item_price)
values(7,'Paint', 'Paint for Room', 1311.40);
insert into item (item_id, item_name, item_desc, item_price)
values(8,'Red paint', 'Red paint for room', 1135.71);
insert into item (item_id, item_name, item_desc, item_price)
values(9,'Household Chairs', 'Chairs for house', 25.71);
insert into item (item_id, item_name, item_desc, item_price)
values(10,'Office Chairs', 'Chairs for office', 395.98);
insert into item (item_id, item_name, item_desc, item_price)
values(11,'Outdoor Chairs', 'Chairs for outdoor activities', 1234.36);

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">tutorialmy5ql</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/spring_hibernate_many_to_many</property>
<property name="hibernate.connection.username">tutorialuser</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.show_sql">false</property>
</session-factory>
</hibernate-configuration>

View File

@ -1,21 +0,0 @@
# jdbc.X
jdbc.driverClassName=org.h2.Driver
jdbc.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
jdbc.eventGeneratedId=sa
jdbc.user=sa
jdbc.pass=
# hibernate.X
hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.show_sql=false
hibernate.hbm2ddl.auto=create-drop
hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=true
hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
# hibernate.search.X
hibernate.search.default.directory_provider = filesystem
hibernate.search.default.indexBase = /data/index/default
# envers.X
envers.audit_table_suffix=_audit_log

View File

@ -1,13 +0,0 @@
*.class
#folders#
/target
/neoDb*
/data
/src/main/webapp/WEB-INF/classes
*/META-INF/*
# Packaged files #
*.jar
*.war
*.ear

View File

@ -1,22 +0,0 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.baeldung.hibernate.criteria.model.Item" table="ITEM">
<id name="itemId" type="java.lang.Integer">
<column name="ITEM_ID" />
<generator class="identity" />
</id>
<property name="itemDescription" type="string">
<column name="ITEM_DESC" length="100" />
</property>
<property name="itemPrice" type="java.lang.Integer">
<column name="ITEM_PRICE" not-null="true" />
</property>
<property name="itemName" type="string">
<column name="ITEM_NAME" not-null="true" />
</property>
</class>
</hibernate-mapping>

View File

@ -1,21 +0,0 @@
insert into item (item_id, item_name, item_desc, item_price) values(1,'item One', 'test 1', 35.12);
insert into item (item_id, item_name, item_desc, item_price) values(2,'Pogo stick', 'Pogo stick', 466.12);
insert into item (item_id, item_name, item_desc, item_price) values(3,'Raft', 'Raft', 345.12);
insert into item (item_id, item_name, item_desc, item_price) values(4,'Skate Board', 'Skating', 135.71);
insert into item (item_id, item_name, item_desc, item_price) values(5,'Umbrella', 'Umbrella for Rain', 619.25);
insert into item (item_id, item_name, item_desc, item_price) values(6,'Glue', 'Glue for home', 432.73);
insert into item (item_id, item_name, item_desc, item_price) values(7,'Paint', 'Paint for Room', 1311.40);
insert into item (item_id, item_name, item_desc, item_price) values(8,'Red paint', 'Red paint for room', 1135.71);
insert into item (item_id, item_name, item_desc, item_price) values(9,'Household Chairs', 'Chairs for house', 25.71);
insert into item (item_id, item_name, item_desc, item_price) values(10,'Office Chairs', 'Chairs for office', 395.98);
insert into item (item_id, item_name, item_desc, item_price) values(11,'Outdoor Chairs', 'Chairs for outdoor activities', 1234.36);

View File

@ -1,6 +1,6 @@
## Hibernate 5 with Spring
## Hibernate Mapping
This module contains articles about Hibernate 5 with Spring.
This module contains articles about Hibernate Mappings.
### Relevant articles

View File

@ -3,9 +3,9 @@
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>
<artifactId>hibernate-many-to-many</artifactId>
<artifactId>hibernate-mapping-2y</artifactId>
<version>0.1-SNAPSHOT</version>
<name>hibernate-many-to-many</name>
<name>hibernate-mapping-2</name>
<parent>
<groupId>com.baeldung</groupId>
@ -19,24 +19,8 @@
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<!-- persistence -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
@ -47,16 +31,6 @@
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>${jta.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-orm</artifactId>
<version>${hibernatesearch.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp</artifactId>
@ -70,53 +44,31 @@
<version>${guava.version}</version>
</dependency>
<!-- test scoped -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>${org.springframework.security.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>${hsqldb.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.2</version>
</dependency>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
<version>${com.sun.xml.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
<version>${javax.xml.bind.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.1</version>
<version>${com.sun.xml.version}</version>
</dependency>
</dependencies>
@ -124,13 +76,11 @@
<!-- Spring -->
<org.springframework.version>5.0.2.RELEASE</org.springframework.version>
<org.springframework.data.version>1.10.6.RELEASE</org.springframework.data.version>
<org.springframework.security.version>4.2.1.RELEASE</org.springframework.security.version>
<!-- persistence -->
<hibernate.version>5.2.10.Final</hibernate.version>
<hibernatesearch.version>5.8.2.Final</hibernatesearch.version>
<tomcat-dbcp.version>9.0.0.M26</tomcat-dbcp.version>
<jta.version>1.1</jta.version>
<hsqldb.version>2.3.4</hsqldb.version>
<com.sun.xml.version>2.3.0.1</com.sun.xml.version>
<javax.xml.bind.version>2.3.1</javax.xml.bind.version>
</properties>
</project>

View File

@ -1,7 +1,9 @@
package com.baeldung.manytomany.spring;
package com.baeldung.manytomany;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.tomcat.dbcp.dbcp2.BasicDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@ -20,7 +22,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@EnableTransactionManagement
@PropertySource({ "classpath:persistence-h2.properties" })
@ComponentScan({ "com.baeldung.hibernate.manytomany" })
@ComponentScan({ "com.baeldung.manytomany" })
public class PersistenceConfig {
@Autowired
@ -30,7 +32,7 @@ public class PersistenceConfig {
public LocalSessionFactoryBean sessionFactory() {
final LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(restDataSource());
sessionFactory.setPackagesToScan(new String[] { "com.baeldung.hibernate.manytomany" });
sessionFactory.setPackagesToScan(new String[] { "com.baeldung.manytomany" });
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;

View File

@ -0,0 +1,8 @@
package com.baeldung.manytomany.dao;
import com.baeldung.manytomany.dao.common.IOperations;
import com.baeldung.manytomany.model.Employee;
public interface IEmployeeDao extends IOperations<Employee>{
}

View File

@ -0,0 +1,8 @@
package com.baeldung.manytomany.dao;
import com.baeldung.manytomany.dao.common.IOperations;
import com.baeldung.manytomany.model.Project;
public interface IProjectDao extends IOperations<Project>{
}

View File

@ -1,4 +1,4 @@
package com.baeldung.persistence.dao.common;
package com.baeldung.manytomany.dao.common;
import java.io.Serializable;

View File

@ -1,4 +1,4 @@
package com.baeldung.persistence.dao.common;
package com.baeldung.manytomany.dao.common;
import java.io.Serializable;
import java.util.List;

View File

@ -1,4 +1,4 @@
package com.baeldung.persistence.dao.common;
package com.baeldung.manytomany.dao.common;
import java.io.Serializable;
import java.util.List;

View File

@ -1,9 +1,10 @@
package com.baeldung.persistence.manytomany.dao.impl;
package com.baeldung.manytomany.dao.impl;
import org.springframework.stereotype.Repository;
import com.baeldung.hibernate.manytomany.model.Employee;
import com.baeldung.persistence.dao.common.AbstractHibernateDao;
import com.baeldung.persistence.manytomany.dao.IEmployeeDao;
import com.baeldung.manytomany.dao.IEmployeeDao;
import com.baeldung.manytomany.dao.common.AbstractHibernateDao;
import com.baeldung.manytomany.model.Employee;
@Repository
public class EmployeeDao extends AbstractHibernateDao<Employee> implements IEmployeeDao {

View File

@ -1,9 +1,10 @@
package com.baeldung.persistence.manytomany.dao.impl;
package com.baeldung.manytomany.dao.impl;
import org.springframework.stereotype.Repository;
import com.baeldung.hibernate.manytomany.model.Project;
import com.baeldung.persistence.dao.common.AbstractHibernateDao;
import com.baeldung.persistence.manytomany.dao.IProjectDao;
import com.baeldung.manytomany.dao.IProjectDao;
import com.baeldung.manytomany.dao.common.AbstractHibernateDao;
import com.baeldung.manytomany.model.Project;
@Repository

View File

@ -1,4 +1,4 @@
package com.baeldung.hibernate.manytomany.model;
package com.baeldung.manytomany.model;
import java.io.Serializable;
import java.util.HashSet;

View File

@ -1,8 +1,9 @@
package com.baeldung.hibernate.manytomany.model;
package com.baeldung.manytomany.model;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;

View File

@ -1,14 +1,15 @@
package com.baeldung.hibernate.manytomany.util;
package com.baeldung.manytomany.util;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import com.baeldung.hibernate.manytomany.model.Employee;
import com.baeldung.hibernate.manytomany.model.Project;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.baeldung.manytomany.model.Employee;
import com.baeldung.manytomany.model.Project;
public class HibernateUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(HibernateUtil.class);

View File

@ -0,0 +1,11 @@
# jdbc.X
jdbc.driverClassName=org.h2.Driver
jdbc.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
jdbc.eventGeneratedId=sa
jdbc.user=sa
jdbc.pass=
# hibernate.X
hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.show_sql=false
hibernate.hbm2ddl.auto=create-drop

View File

@ -6,8 +6,7 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.baeldung.spring.PersistenceConfig;
import com.baeldung.manytomany.PersistenceConfig;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class)

View File

@ -2,6 +2,7 @@ package com.baeldung.hibernate.manytomany;
import java.util.HashSet;
import java.util.Set;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.junit.After;
@ -12,9 +13,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.baeldung.hibernate.manytomany.model.Employee;
import com.baeldung.hibernate.manytomany.model.Project;
import com.baeldung.manytomany.spring.PersistenceConfig;
import com.baeldung.manytomany.PersistenceConfig;
import com.baeldung.manytomany.model.Employee;
import com.baeldung.manytomany.model.Project;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class)

View File

@ -1,10 +1,12 @@
package com.baeldung.hibernate.manytomany;
import static org.junit.Assert.assertNotNull;
import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.junit.After;
@ -13,9 +15,9 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import com.baeldung.hibernate.manytomany.util.HibernateUtil;
import com.baeldung.hibernate.manytomany.model.Employee;
import com.baeldung.hibernate.manytomany.model.Project;
import com.baeldung.manytomany.model.Employee;
import com.baeldung.manytomany.model.Project;
import com.baeldung.manytomany.util.HibernateUtil;
/**
* Configured in: manytomany.cfg.xml

View File

@ -13,4 +13,4 @@
<property name="hibernate.show_sql">false</property>
<property name="hibernate.hbm2ddl.auto">create-drop</property>
</session-factory>
</hibernate-configuration>
</hibernate-configuration>