0

I've got a Spring Boot project connected to a postgresql database, and it seems like Hibernate isn't creating the tables automatically like they did with an h2 database. On startup, my app spits out the following stacktrace:

2017-03-02T01:18:46.415146+00:00 app[web.1]: java.lang.IllegalStateException: Failed to execute ApplicationRunner
2017-03-02T01:18:46.415147+00:00 app[web.1]:    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:794) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
2017-03-02T01:18:46.415148+00:00 app[web.1]:    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:781) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
2017-03-02T01:18:46.415149+00:00 app[web.1]:    at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:771) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
2017-03-02T01:18:46.415150+00:00 app[web.1]:    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
2017-03-02T01:18:46.415150+00:00 app[web.1]:    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
2017-03-02T01:18:46.415151+00:00 app[web.1]:    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
2017-03-02T01:18:46.415152+00:00 app[web.1]:    at com.recipes.Application.main(Application.java:10) [classes!/:na]
2017-03-02T01:18:46.415152+00:00 app[web.1]:    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121-cedar14]
2017-03-02T01:18:46.415153+00:00 app[web.1]:    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121-cedar14]
2017-03-02T01:18:46.415155+00:00 app[web.1]:    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121-cedar14]
2017-03-02T01:18:46.415154+00:00 app[web.1]:    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121-cedar14]
2017-03-02T01:18:46.415156+00:00 app[web.1]:    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [recipe-site-1.0-SNAPSHOT.jar:na]
2017-03-02T01:18:46.415156+00:00 app[web.1]:    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [recipe-site-1.0-SNAPSHOT.jar:na]
2017-03-02T01:18:46.415157+00:00 app[web.1]:    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [recipe-site-1.0-SNAPSHOT.jar:na]
2017-03-02T01:18:46.415158+00:00 app[web.1]:    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58) [recipe-site-1.0-SNAPSHOT.jar:na]
2017-03-02T01:18:46.415159+00:00 app[web.1]: Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
2017-03-02T01:18:46.415160+00:00 app[web.1]:    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:261) ~[spring-orm-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
2017-03-02T01:18:46.415160+00:00 app[web.1]:    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:244) ~[spring-orm-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
2017-03-02T01:18:46.415161+00:00 app[web.1]:    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:491) ~[spring-orm-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
2017-03-02T01:18:46.415163+00:00 app[web.1]:    at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59) ~[spring-tx-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
2017-03-02T01:18:46.415164+00:00 app[web.1]:    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147) ~[spring-tx-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
2017-03-02T01:18:46.415164+00:00 app[web.1]:    at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213) ~[spring-tx-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
2017-03-02T01:18:46.415165+00:00 app[web.1]:    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
2017-03-02T01:18:46.415166+00:00 app[web.1]:    at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133) ~[spring-data-jpa-1.10.3.RELEASE.jar!/:na]
2017-03-02T01:18:46.415166+00:00 app[web.1]:    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
2017-03-02T01:18:46.415167+00:00 app[web.1]:    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
2017-03-02T01:18:46.415168+00:00 app[web.1]:    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
2017-03-02T01:18:46.415174+00:00 app[web.1]:    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
2017-03-02T01:18:46.415175+00:00 app[web.1]:    at com.sun.proxy.$Proxy104.findAll(Unknown Source) ~[na:na]
2017-03-02T01:18:46.415176+00:00 app[web.1]:    at com.recipes.service.UserServiceImpl.findAll(UserServiceImpl.java:22) ~[classes!/:na]
2017-03-02T01:18:46.415177+00:00 app[web.1]:    at com.recipes.config.DatabaseLoader.run(DatabaseLoader.java:40) ~[classes!/:na]
2017-03-02T01:18:46.415177+00:00 app[web.1]:    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:791) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
2017-03-02T01:18:46.415178+00:00 app[web.1]:    ... 14 common frames omitted
2017-03-02T01:18:46.415179+00:00 app[web.1]: Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
2017-03-02T01:18:46.415180+00:00 app[web.1]:    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:106) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415180+00:00 app[web.1]:    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415181+00:00 app[web.1]:    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415182+00:00 app[web.1]:    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415183+00:00 app[web.1]:    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:79) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415183+00:00 app[web.1]:    at org.hibernate.loader.Loader.getResultSet(Loader.java:2117) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415184+00:00 app[web.1]:    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1900) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415185+00:00 app[web.1]:    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1876) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415185+00:00 app[web.1]:    at org.hibernate.loader.Loader.doQuery(Loader.java:919) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415186+00:00 app[web.1]:    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415187+00:00 app[web.1]:    at org.hibernate.loader.Loader.doList(Loader.java:2617) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415187+00:00 app[web.1]:    at org.hibernate.loader.Loader.doList(Loader.java:2600) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415188+00:00 app[web.1]:    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2429) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415189+00:00 app[web.1]:    at org.hibernate.loader.Loader.list(Loader.java:2424) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415189+00:00 app[web.1]:    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:501) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415190+00:00 app[web.1]:    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:371) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415191+00:00 app[web.1]:    at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415192+00:00 app[web.1]:    at org.hibernate.internal.QueryImpl.list(QueryImpl.java:87) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415191+00:00 app[web.1]:    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1326) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415194+00:00 app[web.1]:    at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:483) ~[hibernate-entitymanager-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415195+00:00 app[web.1]:    at org.hibernate.jpa.criteria.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:50) ~[hibernate-entitymanager-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415193+00:00 app[web.1]:    at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:606) ~[hibernate-entitymanager-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415195+00:00 app[web.1]:    at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:327) ~[spring-data-jpa-1.10.3.RELEASE.jar!/:na]
2017-03-02T01:18:46.415196+00:00 app[web.1]:    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121-cedar14]
2017-03-02T01:18:46.415197+00:00 app[web.1]:    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121-cedar14]
2017-03-02T01:18:46.415197+00:00 app[web.1]:    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121-cedar14]
2017-03-02T01:18:46.415202+00:00 app[web.1]:    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:503) ~[spring-data-commons-1.12.3.RELEASE.jar!/:na]
2017-03-02T01:18:46.415203+00:00 app[web.1]:    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:488) ~[spring-data-commons-1.12.3.RELEASE.jar!/:na]
2017-03-02T01:18:46.415198+00:00 app[web.1]:    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121-cedar14]
2017-03-02T01:18:46.415204+00:00 app[web.1]:    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460) ~[spring-data-commons-1.12.3.RELEASE.jar!/:na]
2017-03-02T01:18:46.415208+00:00 app[web.1]:    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
2017-03-02T01:18:46.415209+00:00 app[web.1]:    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61) ~[spring-data-commons-1.12.3.RELEASE.jar!/:na]
2017-03-02T01:18:46.415210+00:00 app[web.1]:    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
2017-03-02T01:18:46.415210+00:00 app[web.1]:    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
2017-03-02T01:18:46.415211+00:00 app[web.1]:    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) ~[spring-tx-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
2017-03-02T01:18:46.415212+00:00 app[web.1]:    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
2017-03-02T01:18:46.415213+00:00 app[web.1]:    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
2017-03-02T01:18:46.415213+00:00 app[web.1]:    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
2017-03-02T01:18:46.415214+00:00 app[web.1]:    ... 24 common frames omitted
2017-03-02T01:18:46.415215+00:00 app[web.1]: Caused by: org.postgresql.util.PSQLException: ERROR: column user0_.id does not exist
2017-03-02T01:18:46.415216+00:00 app[web.1]:   Position: 66
2017-03-02T01:18:46.415216+00:00 app[web.1]:    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412) ~[postgresql-42.0.0.jre7.jar!/:42.0.0.jre7]
2017-03-02T01:18:46.415217+00:00 app[web.1]:    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2125) ~[postgresql-42.0.0.jre7.jar!/:42.0.0.jre7]
2017-03-02T01:18:46.415218+00:00 app[web.1]:    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:297) ~[postgresql-42.0.0.jre7.jar!/:42.0.0.jre7]
2017-03-02T01:18:46.415219+00:00 app[web.1]:    at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428) ~[postgresql-42.0.0.jre7.jar!/:42.0.0.jre7]
2017-03-02T01:18:46.415219+00:00 app[web.1]:    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354) ~[postgresql-42.0.0.jre7.jar!/:42.0.0.jre7]
2017-03-02T01:18:46.415220+00:00 app[web.1]:    at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:169) ~[postgresql-42.0.0.jre7.jar!/:42.0.0.jre7]
2017-03-02T01:18:46.415220+00:00 app[web.1]:    at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:117) ~[postgresql-42.0.0.jre7.jar!/:42.0.0.jre7]
2017-03-02T01:18:46.415221+00:00 app[web.1]:    at org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:82) ~[tomcat-dbcp-8.5.6.jar!/:8.5.6]
2017-03-02T01:18:46.415222+00:00 app[web.1]:    at org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:82) ~[tomcat-dbcp-8.5.6.jar!/:8.5.6]
2017-03-02T01:18:46.415222+00:00 app[web.1]:    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
2017-03-02T01:18:46.415223+00:00 app[web.1]:    ... 57 common frames omitted

I've got a DatabaseLoader class that auto-generates data on startup, and that's the ApplicationRunner that's failing to run. Here are the relevant classes:

User.java

@Entity
public class User extends GenericEntity {
    public static final PasswordEncoder PASSWORD_ENCODER = new BCryptPasswordEncoder();
    private String username;
    @JsonIgnore
    private String password;
    @JsonIgnore
    private String[] roles;
    @OneToMany(mappedBy = "createdBy")
    private List<Recipe> createdRecipes;
    @ManyToMany
    private List<Recipe> favoritedRecipes;

    public User() {
        super();
        createdRecipes = new ArrayList<>();
        favoritedRecipes = new ArrayList<>();
    }

    public User(String username, String password, String[] roles) {
        this();
        this.username = username;
        this.roles = roles;
        setPassword(password);
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = PASSWORD_ENCODER.encode(password);
    }

    public String[] getRoles() {
        return roles;
    }

    public void setRoles(String[] roles) {
        this.roles = roles;
    }

    public List<Recipe> getCreatedRecipes() {
        return createdRecipes;
    }

    public void setCreatedRecipes(List<Recipe> createdRecipes) {
        this.createdRecipes = createdRecipes;
    }

    public List<Recipe> getFavoritedRecipes() {
        return favoritedRecipes;
    }

    public void setFavoritedRecipes(List<Recipe> favoritedRecipes) {
        this.favoritedRecipes = favoritedRecipes;
    }

    public void addCreatedRecipe(Recipe recipe) {
        createdRecipes.add(recipe);
    }

    public void addFavoritedRecipe(Recipe recipe) {
        favoritedRecipes.add(recipe);
    }

    public void removeCreatedRecipe(Recipe recipe) {
        createdRecipes.remove(recipe);
    }

    public void removeFavoritedRecipe(Recipe recipe) {
        favoritedRecipes.remove(recipe);
    }

    public boolean isAdmin() {
        for(int i = 0; i < roles.length; i++) {
            if(roles[i].equals("ROLE_ADMIN")) {
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

        return username.equals(user.username) && user.getId() == this.getId();
    }
}

DatabaseLoader.java

@Component
public class DatabaseLoader implements ApplicationRunner {
    private UserService users;
    private IngredientService ingredients;
    private RecipeRepository recipes;
    private CategoryService categories;

    @Autowired
    public DatabaseLoader(UserService users, IngredientService ingredients, RecipeRepository recipes, CategoryService categories) {
        this.users = users;
        this.ingredients = ingredients;
        this.recipes = recipes;
        this.categories = categories;
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        if((users.findAll()).isEmpty()) {
            User admin = new User("admin", "password", new String[]{"ROLE_ADMIN", "ROLE_USER"});
            User nonAdmin = new User("non-admin", "password", new String[]{"ROLE_USER"});
            users.save(admin);
            users.save(nonAdmin);
            Ingredient ingredient = new Ingredient("pizza", "pie", 1);
            ingredients.save(ingredient);
            Category american = new Category("American");
            Category italian = new Category("Italian");
            categories.save(american);
            categories.save(italian);
            Recipe pizza = new Recipe.RecipeBuilder("Pizza", american)
                    .addIngredient(ingredient)
                    .setDescription("Mmm... Delicious pizza")
                    .setCookTime(15)
                    .setPrepTime(5)
                    .addInstruction("Place pizza in oven", 0)
                    .addInstruction("Cook pizza for 15 minutes", 1)
                    .setImage("http://kingrichiespizza.com/wp-content/uploads/2015/12/d5a3498cfc9e53130b5f815ef44713b7_Jet.jpg")
                    .build();
            pizza.setCreatedBy(admin);
            Recipe burger = new Recipe.RecipeBuilder("Burger", american).build();
            burger.setCreatedBy(admin);
            Recipe spaghetti = new Recipe.RecipeBuilder("Spaghetti", italian).build();
            spaghetti.setCreatedBy(nonAdmin);
            admin.addFavoritedRecipe(spaghetti);
            recipes.save(pizza);
            recipes.save(burger);
            recipes.save(spaghetti);
            users.save(admin);
        } else {
            Application.main(args.getSourceArgs());
        }
    }
}

and the GenericEntity.java

@MappedSuperclass
public abstract class GenericEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Version
    private Long version;

    public GenericEntity() {
        id = null;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getVersion() {
        return version;
    }

    public void setVersion(Long version) {
        this.version = version;
    }
}

Here is my database configuration class:

@Configuration
public class DataConfig {
    @Bean
    public BasicDataSource dataSource() throws URISyntaxException {
        String dbUrl = System.getenv("JDBC_DATABASE_URL");
        String username = System.getenv("JDBC_DATABASE_USERNAME");
        String password = System.getenv("JDBC_DATABASE_PASSWORD");

        BasicDataSource basicDataSource = new BasicDataSource();
        basicDataSource.setUrl(dbUrl);
        basicDataSource.setUsername(username);
        basicDataSource.setPassword(password);

        return basicDataSource;
    }
}

and my application.properties:

spring.data.rest.base-path = /api/v1
spring.datasource.schema = update
spring.datasource.name = recipes
spring.datasource.driver-class-name = org.postgresql.Driver
spring.jpa.show-sql = true
spring.jpa.properties.hibernate.format_sql = true
spring.jpa.properties.hibernate.use_sql_comments = true
restart.include.all=.*

Is there a configuration I'm missing that's causing this to happen? Thanks in advance

2
  • if db is not embedde spring.jpa.hibernate.ddl-auto is none. try set it up to create. docs.spring.io/spring-boot/docs/current/reference/html/… Commented Mar 2, 2017 at 10:48
  • @SergiiGetman - I've added this property, but it doesn't seem to have created it. I'm still getting the same error Commented Mar 2, 2017 at 22:36

2 Answers 2

1

I think you missed id field with sequence declaration
Usually I'm declaring entity like this...

@Entity
@Table(name = "user")
@SequenceGenerator(name = "user_id_seq", sequenceName = "user_id_seq", allocationSize = 1)
public class User implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_id_seq")
private Long id;
... rest of your entity
}
Sign up to request clarification or add additional context in comments.

2 Comments

its entity mapped to superclass with id
Yeah, I have a GenericEntity that has the id field, which the User extends
0

Trying to recall but I think you have to create identity table in postgres..probably that is what causes it.

1 Comment

So that's not automatically generated by Hibernate?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.