Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I am trying code first approach to create database using Spring Boot and Hibernate.

But, I am not able to do that yet.

Please suggest how can I Solve this.

Here is my POM

<?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.inventory</groupId>
<artifactId>publisherinventory</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>PublisherInventory</name>
<description>project for publishers inventory</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.5.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</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-thymeleaf</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>

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.4.1208</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.2.0.Final</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.1.0.Final</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <version>1.0.0.Final</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-releases</id>
        <url>https://repo.spring.io/libs-release</url>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>spring-releases</id>
        <url>https://repo.spring.io/libs-release</url>
    </pluginRepository>
</pluginRepositories>

Here is application.properties

spring.datasource.driverClassName = org.postgresql.Driver
spring.datasource.url= jdbc:postgresql://localhost:5432/BookInventory
spring.datasource.username=postgres
spring.datasource.password=root
spring.jpa.database=POSTGRESQL
spring.jpa.show-sql=true
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL94Dialect
spring.jpa.hibernate.ddl-auto=create

Here is my Enity

package com.inventory.model;

import javax.persistence.*;

@Entity
public class BookGroup{

@Column(name="groupName")
public String getGroupName() {
    return groupName;
}

public void setGroupName(String groupName) {
    this.groupName = groupName;
}

@Id
@Column(name="groupId", unique = true)
@GeneratedValue
public int getGroupId() {
    return groupId;
}

private String groupName;
private int groupId;
}

Here is my Controller

package com.inventory.controllers;

import com.inventory.model.BookGroup;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.validation.Valid;


@Controller
public class BookGroupController {

BookGroup aBookGroup = new BookGroup();

@RequestMapping(value = "/bookGroupEntry", method = RequestMethod.GET)
public String bookGroupEntryForm(Model model){
    model.addAttribute("bookGroup",aBookGroup); // "bookGroup" ->BookGroup (Class Name)
    return "bookGroupEntry";
}

@RequestMapping(value = "/showBookGroups", method = RequestMethod.POST )
public String bookGroupSubmit(@ModelAttribute @Valid BookGroup aBookGroup, Model model){

    return "showBookGroups";
}

}
share|improve this question
1  
stackoverflow.com/questions/26881739/… Maybe not an exact duplicate, but you should read it and turn over every stone. – Tim Biegeleisen Jun 20 at 11:02
    
@Tareq did you get same error? exception? – cralfaro Jun 20 at 11:02
    
For starters you are mixing hibernate 5.1 and 5.2 jars. And hibernate 5.2 isn't supported by the version of Spring Boot and Spring you are using. – M. Deinum Jun 20 at 11:54

I had similar issue. The problem was with wrong set of properties. Have a look here: Spring Boot + Hibernate + Postgres - not creating tables

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.