0

I'm writing a REST Api in Spring, when I try to run the application, I get a huge error log. I think this is what triggers the whole problem.

    2016-07-04 21:25:28.267  INFO 532 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
    2016-07-04 21:25:28.282  INFO 532 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
    2016-07-04 21:25:28.284  INFO 532 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.0.36
    2016-07-04 21:25:28.398  INFO 532 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
    2016-07-04 21:25:28.399  INFO 532 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2417 ms
    2016-07-04 21:25:29.142  INFO 532 --- [ost-startStop-1] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
    2016-07-04 21:25:29.153  INFO 532 --- [ost-startStop-1] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
        name: default
        ...]
    2016-07-04 21:25:29.236  INFO 532 --- [ost-startStop-1] org.hibernate.Version                    : HHH000412: Hibernate Core {4.3.11.Final}
    2016-07-04 21:25:29.238  INFO 532 --- [ost-startStop-1] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
    2016-07-04 21:25:29.240  INFO 532 --- [ost-startStop-1] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
    2016-07-04 21:25:29.453  INFO 532 --- [ost-startStop-1] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
    2016-07-04 21:25:29.517  INFO 532 --- [ost-startStop-1] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
    2016-07-04 21:25:29.729 ERROR 532 --- [ost-startStop-1] o.s.b.c.embedded.tomcat.TomcatStarter    : Error starting Tomcat context: org.springframework.beans.factory.BeanCreationException
    2016-07-04 21:25:29.774  WARN 532 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
    2016-07-04 21:25:29.793 ERROR 532 --- [           main] o.s.boot.SpringApplication               : Application startup failed

The root cause of the failure is:

Caused by: org.hibernate.MappingException: Could not determine type for: java.util.List, at table: comment, for columns: [org.hibernate.mapping.Column(responses)]
    at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:349) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:322) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.mapping.Property.isValid(Property.java:241) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:496) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.mapping.RootClass.validate(RootClass.java:270) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.cfg.Configuration.validate(Configuration.java:1360) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1851) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
    ... 200 common frames omitted

This is my gradle build file,

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath('org.springframework.boot:spring-boot-gradle-plugin:1.3.6.RELEASE')
    }
}

apply plugin: 'java'
apply plugin: 'spring-boot'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {

    compile 'org.springframework.boot:spring-boot-starter-data-rest'
    compile 'org.springframework.boot:spring-boot-starter-data-jpa'
    compile 'com.h2database:h2'
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

This is my Application Class

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

I can't seem to understand what's going wrong here. The source is available at https://github.com/soumasish/Bulletin-Board-Rest-Api Any help appreciated.

Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
  • Can you post full error log? – Sundararaj Govindasamy Jul 05 '16 at 01:47
  • It's too long and won't fit into the 30000 word limit of stackoverflow. That's why I've posted the link to the source code. –  Jul 05 '16 at 01:51
  • Is it possible to find "relevant" error log from that too long and post it here? So that others can try... – Sundararaj Govindasamy Jul 05 '16 at 01:55
  • the one thing you didn't post in your question (stacktrace) is the most important piece... At the very least, the first line + the causes... "at org.spr,,," ? – alexbt Jul 05 '16 at 01:57
  • I've updated the stack trace, but there's still more which I can't fit into the word limit. –  Jul 05 '16 at 02:00
  • perhaps you could include the whole stack trace in your github repo ? I get the feeling we still don't have the root cause of your error – alexbt Jul 05 '16 at 02:08
  • example: http://stackoverflow.com/questions/31161042/hibernate-ogm-persistenceunit-person-unable-to-build-hibernate-sessionfacto – alexbt Jul 05 '16 at 02:08
  • @Alex Possible, I cant fit in more, would request if you might want to check out the repo from github. –  Jul 05 '16 at 02:13
  • The answer is in the second to last line of your stacktrace ... There is something going on with repositories/hibernate/jpa dependencies.... – jny Jul 05 '16 at 02:23
  • There is nothing wrong with the example provided, I've tried it myself on a new project and works well. * Check that your port `8080` is not used by some other application or that you don't have other Tomcat instances running. * You can check also that IntelliJ is closed if you are running the application using the task `bootRun` – Fede Jul 05 '16 at 02:24
  • I'm just doing an application->run, the port is also not taken. But I continue to get the same error. –  Jul 05 '16 at 02:28
  • The error message shows that you have some entity, mapped to a tablke comment, and having a field of type List named responses, that is not mapped correctly. Post the relevant code. – JB Nizet Jul 05 '16 at 05:57

1 Answers1

1

You haven't included any mapping information in your entities. You need to use @OneToMany and @ManyToOne so that Hibernate knows how your entities relate to each other.

Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242