Spring boot connection with mysql workbecnch - spring-boot

I created a spring boot maven project using STS eclipse
In application.properties
spring.datasource.url = jdbc:mysql://localhost:3306/crud
spring.datasource.username = root
spring.datasource.password = root
spring.jpa.hibernate.ddl-auto = update
I created Player entity class, then I run the project but in my workbench there is no table created. Is that because spring boot not connect with db? Then how can I overcome this problem.
This is my pom.xml
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
This is player Entity
#Entity
#Table(name = "PLAYER")
public class Player {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "PLAYER_ID")
private int id;
#Column(name = "PLAYER_NAME")
private String playerName;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getPlayerName() {
return playerName;
}
public void setPlayerName(String playerName) {
this.playerName = playerName;
}
}

Maybe you didn't create the Database.
You try to create the database or replace the connection string with the following:
spring.datasource.url = jdbc:mysql://localhost:3306/crud?createDatabaseIfNotExist=true
UPDATE
Please add the following dependency in your pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
and delete the following dependency:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>

Related

Failed to initialize JPA EntityManagerFactory: Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException

I'm working on Spring boot project.
Actually, refactoring code.
And getting this mistake as follows:
Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not determine type for: ru.kataproject.p_sm_airlines_1.entity.Document, at table: passenger, for columns: [org.hibernate.mapping.Column(document)]
Any ideas?
Document.java
import lombok.Getter;
import lombok.Setter;
import ru.kataproject.p_sm_airlines_1.util.enums.DocumentType;
import javax.persistence.*;
import java.time.LocalDateTime;
#Entity
#Getter
#Setter
#Table(name="document")
public class Document {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY, generator = "document_gen")
#SequenceGenerator(name = "document_gen", sequenceName = "document_sequence", allocationSize = 1)
#Column(name = "id", nullable = false)
private Long id;
#Column(name = "document_type", nullable = false)
private DocumentType documentType;
#Column(name = "document_number")
private String documentNumber;
#Column(name = "registration_address")
private String registrationAddress;
#Column(name = "where_issued")
private String whereIssued;
#Column(name = "department_code")
private String departmentCode;
#Column(name = "date_of_issue")
private LocalDateTime dateOfIssue;
//todo one to one link to person entity
#Column(name = "person")
private String person = "link to person entity";
}
Passenger.java
import lombok.*;
import javax.persistence.*;
import java.time.LocalDate;
#Getter
#Setter
#Entity
#AllArgsConstructor
#NoArgsConstructor
#Table(name = "passenger", schema = "public")
public class Passenger {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name="id")
private Long id;
#NonNull
#Column(name="document")
private Document document; // Заглушка , здесь должна быть сущность Document
#NonNull
#Column(name="email")
private String email;
#NonNull
#Column(name="first_name")
private String first_name;
#NonNull
#Column(name="last_name")
private String last_name;
#NonNull
#Column(name="middle_name")
private String middle_name;
#NonNull
#Column(name="date_of_birth")
private LocalDate date_of_birth;
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ru.kataproject</groupId>
<artifactId>airline_project_1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>airline_project_1</name>
<description>Реализуем функционал авиакомпании на базе прототипа</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<springdoc.openapi.version>1.4.8</springdoc.openapi.version>
<apache-httpcomponents-version>4.5.13</apache-httpcomponents-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${springdoc.openapi.version}</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-data-rest</artifactId>
<version>${springdoc.openapi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${apache-httpcomponents-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.7.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.5.0</version>
</dependency>
<dependency>
<groupId>org.thingsboard</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>1.17.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.17.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.17.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-starter</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.keycloak.bom</groupId>
<artifactId>keycloak-adapter-bom</artifactId>
<version>12.0.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
You should map entities with #ManyToOne or #OneToOne i.e.
#NonNull
#ManyToOne(fetch = LAZY)
#JoinColumn(name="document")
private Document document;

Spring boot app getting "Error creating bean with name 'cassandraSession'"

I'm experiencing some troubles with Apache Cassandra and I think you could help me out!
So, this is my pom
<groupId>com.inboxapp</groupId>
<artifactId>inbox-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>inbox-app</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
</dependency>
<dependency>
<groupId>org.ocpsoft.prettytime</groupId>
<artifactId>prettytime</artifactId>
<version>5.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
These are my classes:
#Table(value = "folders_by_user")
public class Folder {
#PrimaryKeyColumn(name = "user_id", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
private String id;
#PrimaryKeyColumn(name = "label", ordinal = 1, type = PrimaryKeyType.CLUSTERED, ordering = Ordering.ASCENDING)
#CassandraType(type = CassandraType.Name.TEXT)
private String label;
// #PrimaryKeyColumn(name = "created_time_uuid", ordinal = 2, type = PrimaryKeyType.CLUSTERED, ordering = Ordering.ASCENDING)
// #CassandraType(type = CassandraType.Name.TEXT)
// private UUID createdTimeUuid;
#CassandraType(type = CassandraType.Name.TEXT)
private String color;
#Transient
private int unreadCount;
The config class:
#Configuration
#ConfigurationProperties(prefix = "datastax.astra")
public class DataStaxAstraProperties {
private File secureConnectBundle;
public File getSecureConnectBundle() {
return secureConnectBundle;
}
public void setSecureConnectBundle(File secureConnectBundle) {
this.secureConnectBundle = secureConnectBundle;
}
}
And the main:
#SpringBootApplication
#RestController
public class SpringGitHubLoginApplication {
public static void main(String[] args) {
SpringApplication.run(SpringGitHubLoginApplication.class, args);
}
#Bean
public CqlSessionBuilderCustomizer sessionBuilderCustomizer(DataStaxAstraProperties astraProperties) {
Path bundle = astraProperties.getSecureConnectBundle().toPath();
return builder -> builder.withCloudSecureConnectBundle(bundle);
}
}
There's soomething missing that I'm not seeing or what? As far as I can see there's no annotation missing. I've to say that I've done also the repository (not included here).
Thanks in adnvace!

Problem inserting entities in database with #BeforeAll

i'm trying to insert some entities in my H2 database to run some unit tests, for this im using a setup method decorated with the #BeforeAll annotation like so :
#RunWith(SpringRunner.class)
#DataJpaTest
public class ItemRepositoryTest {
#Autowired
private ItemRepository itemRepo;
#Autowired
private CategoryRepository catRepo;
#BeforeAll
public static void setup(#Autowired ItemRepository itemRepo) {
Category cat_0 = new Category(0L, "category_0");
Category cat_1 = new Category(1L, "category_1");
Category cat_2 = new Category(2L, "category_2");
Item item_0 = new Item(0L, "item_0", "...", 7.99, "0000000000000", "imgUrl", Set.of(cat_0, cat_1));
Item item_1 = new Item(1L, "item_1", "...", 8.99, "1111111111111", "imgUrl", Set.of(cat_2));
Item item_2 = new Item(2L, "item_2", "...", 9.99, "2222222222222", "imgUrl", Set.of(cat_0, cat_1, cat_2));
itemRepo.saveAll(List.of(item_0, item_1, item_2));
}
#AfterAll
public static void clean(#Autowired ItemRepository itemRepo, #Autowired CategoryRepository catRepo) {
itemRepo.deleteAll();
catRepo.deleteAll();
}
#Test
public void items_should_have_been_saved() {
List<Item> items = itemRepo.findAll();
assertThat(items).hasSize(3);
}
}
The 'items_should_have_been_saved' Test fails (Expected size: 3 but was: 0), it seems my 'setup' method does not work, can anybody tell me what im doing wrong ? (I'm using SpringBoot 2.5.0)
src/test/resources/aplication.properties:
#----------------------------------------------------------------------------------
# CONFIG H2
#----------------------------------------------------------------------------------
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=TRUE;IGNORECASE=TRUE;
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=sa
spring.jpa.show-sql=true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
spring.jpa.defer-datasource-initialization=true
#----------------------------------------------------------------------------------
server.error.include-message=always
spring.sql.init.platform=h2
pom.xml:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>net.kaczmarzyk</groupId>
<artifactId>specification-arg-resolver</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

SpringBoot 2 and SDN 5 Unit Test hangs after start

I'm trying to migrate to SpringBoot 2 and SDN 5, working on just getting a unit test running. My test code:
#SpringBootTest
#ContextConfiguration(classes = com.playerscoach.auth.context.PersistenceContext.class)
#RunWith(SpringRunner.class)
public class AthleteRepositoryTest {
private static final Logger log = LoggerFactory.getLogger(AthleteRepositoryTest.class);
#Autowired
UserRepository userRepository;
#Autowired
private Session session;
#Autowired
private AthleteRepository athleteRepo;
private GraphDatabaseService graphDb;
private GraphAwareRuntime runtime;
#Before
public void setUp() {
GraphDatabaseService graphDb = new GraphDatabaseFactory()
.newEmbeddedDatabase(new File("var/graphDb"));
GraphAwareRuntime runtime = GraphAwareRuntimeFactory
.createRuntime(graphDb);
}
#After
public void tearDown() {
session.purgeDatabase();
}
/**
* Test of findByTitle method, of class MovieRepository.
*/
#Test
public void testFindByEmail() {
Athlete athlete = new Athlete.Builder()
.firstName("Alper")
.lastName("Akture")
.emailAddress("alper#test.com")
.password("password").build();
athleteRepo.save(athlete);
String email = "alper#test.com";
Collection<Athlete> result = athleteRepo.findByEmailAddress(email);
assertThat(result, notNullValue());
assertThat(result.iterator().next().getPassword(), is("password"));
}
#Test
public void testFindByLastName() {
String lastName = "Akture";
Collection<Athlete> result = athleteRepo.findByLastName(lastName);
assertThat(result, notNullValue());
assertThat(result.iterator().next().getPassword(), is("password"));
}
}
My repository:
public interface AthleteRepository extends Neo4jRepository<Athlete, Long> {
Collection<Athlete> findByEmailAddress(#Param("emailAddress") String emailAddress);
Collection<Athlete> findByLastName(#Param("lastName") String lastName);
#Query("MATCH (a:Athlete) WHERE a.emailAddress =~ ('(?i).*'+{emailAddress}+'.*') RETURN a")
Collection<Athlete> findByEmailContaining(#Param("emailAddress") String emailAddress);
}
My pom:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.M4</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<neo4j-ogm.version>3.0.0</neo4j-ogm.version>
<spring-data-releasetrain.version>Kay-RELEASE</spring-data-releasetrain.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- uncomment to use embedded -->
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-embedded-driver</artifactId>
<version>${neo4j-ogm.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>3.1.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.playerscoach.lib</groupId>
<artifactId>lib</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.graphaware.neo4j</groupId>
<artifactId>timetree</artifactId>
<version>3.2.1.51.27</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.graphaware.neo4j/graphaware-framework-embedded -->
<dependency>
<groupId>com.graphaware.neo4j</groupId>
<artifactId>graphaware-framework-embedded</artifactId>
<version>3.2.5.51</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.graphaware.neo4j</groupId>
<artifactId>tests</artifactId>
<version>3.2.5.51</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
<version>1.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.neo4j.test</groupId>
<artifactId>neo4j-harness</artifactId>
<version>3.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-kernel</artifactId>
<version>3.1.0</version>
<type>test-jar</type>
</dependency>
When I run the test, it hangs with the last line output in the log file:
07:53:03.526 [main] DEBUG org.springframework.boot.context.logging.ClasspathLoggingApplicationListener - Application failed to start with classpath:
with a dump of the entire classpath.
Any idea where I went wrong?

Error creating bean with the name localContainerEntityManagerFactorryBean defined in the class path resource hibernateconfig.class

I'm getting the Error creating bean with the name localContainerEntityManagerFactorryBean defined in the class path resource hibernateconfig.class. nested exception is javax.persistence.persistenceException:unable to build hibernate session factory: A foreign key referring organizer from events has the wrong no of column, should be 2.
My pom file is
<?xml version="1.0" encoding="UTF-8"?>
<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>com.EventToday</groupId>
<artifactId>EventToday</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>EventToday</name>
<description>projects for events</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<springframework.version>4.0.6.RELEASE</springframework.version>
<hibernate.version>4.3.6.Final</hibernate.version>
<mysql.version>5.1.31</mysql.version>
<joda-time.version>2.3</joda-time.version>
<testng.version>6.9.4</testng.version>
<mockito.version>1.10.19</mockito.version>
<h2.version>1.4.187</h2.version>
<dbunit.version>2.2</dbunit.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>ejb3-persistence</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<!-- jsr303 validation -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.0.2.GA</version>
</dependency>
<!-- MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<!-- Joda-Time -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<!-- To map JodaTime with database type -->
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>3.0.0.CR1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<warName>EventToday</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
<compilerArgs>
<arg>-Aopenjpa.metamodel=true</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
and hibernate configuration
#Configuration
#EnableTransactionManagement
#EnableJpaRepositories("com.EventToday.event.repository")
#ComponentScan({ "com.EventToday.event" })
#PropertySource(value = { "classpath:application.properties" })
public class hibernateconfig {
#Autowired
private Environment environment;
#Bean
public LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean() {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setDatabase(Database.MYSQL);
//vendorAdapter.setGenerateDdl(generateDDL);
vendorAdapter.setShowSql(true);
LocalContainerEntityManagerFactoryBean beanFactory = new LocalContainerEntityManagerFactoryBean();
beanFactory.setJpaVendorAdapter(vendorAdapter);
beanFactory.setPackagesToScan("com.EventToday.event.model");
beanFactory.setDataSource(dataSource());
//beanFactory.afterPropertiesSet();
beanFactory.setJpaProperties(hibernateProperties());
return beanFactory;
}
#Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(environment.getRequiredProperty("spring.datasource.driverClassName"));
dataSource.setUrl(environment.getRequiredProperty("spring.datasource.url"));
dataSource.setSchema(environment.getRequiredProperty("spring.datasource.schema"));
dataSource.setUsername(environment.getRequiredProperty("spring.datasource.username"));
dataSource.setPassword(environment.getRequiredProperty("spring.datasource.password"));
return dataSource;
}
private Properties hibernateProperties() {
Properties properties = new Properties();
properties.put("spring.jpa.properties.hibernate.dialect", environment.getRequiredProperty("spring.jpa.properties.hibernate.dialect"));
properties.put("spring.jpa.show_sql", environment.getRequiredProperty("spring.jpa.show-sql"));
properties.put("spring.jpa.properties.hibernate.format_sql", environment.getRequiredProperty("spring.jpa.properties.hibernate.format_sql"));
return properties;
}
#Bean
public EntityManagerFactory entityManagerFactory(){
return localContainerEntityManagerFactoryBean().getObject();
}
#Bean
public EntityManager entityManager(){
return entityManagerFactory().createEntityManager();
}
#Bean
PlatformTransactionManager transactionManager(){
JpaTransactionManager manager = new JpaTransactionManager();
manager.setEntityManagerFactory(entityManagerFactory());
return manager;
}
#Bean
public HibernateExceptionTranslator hibernateExceptionTranslator(){
return new HibernateExceptionTranslator();
}
}
organizer
#Entity
#Table(name="organizer")
public class Organizer extends BaseEntity{
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private int roid;
#Column(name="orgNname", nullable=false)
private String organizerName;
#Column(name = "org_contact", nullable = false)
private String orgTelephone;
#Column(name = "org_altcontact", nullable = false)
private String orgContact;
#Column(name = "org_mail_address", nullable = false)
private String mailAddress;
#Column(name = "org_address", nullable = false)
private String orgAddress;
#OneToMany(mappedBy = "organizer")
private Set<events> evts;
public Set<events> getEvts() {
return evts;
}
public void setEvts(Set<events> evts) {
this.evts = evts;
}
public Organizer() {
}
//getters and setters
}
#events
#Entity
#Table(name="event")
public class events extends BaseEntity{
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
#ManyToOne
#JoinColumn(name = "roid")
private Organizer organizer;
public events() {
}
#Column(name = "event_name", nullable = false)
private String eventname;
#Column(name = "event_date", nullable = false)
#DateTimeFormat(pattern="dd/MM/yyyy")
#Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
private LocalDate date;
#NotNull
#Digits(integer=8, fraction=2)
#Column(name = "ticket_price", nullable = false)
private BigDecimal price;
#Column(name="event_location", nullable=false)
private String location;
#Column(name="happening_city", nullable=false)
private String Address;
#Column(name="contact_no", nullable=false)
private String contact_no;
#Column(name="alt_contact_no", nullable=false)
private String alternate_contact;
#Column(name="mail_address")
private String mail_address;
//getters and setters
}

Resources