我在Spring编写REST Api,当我尝试运行应用程序时,我收到了一个巨大的错误日志。我认为这是触发整个问题的原因。
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
失败的根本原因是:
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
这是我的gradle构建文件,
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'
}
这是我的应用程序类
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
我似乎无法理解这里出了什么问题。来源可在 https://github.com/soumasish/Bulletin-Board-Rest-Api 任何帮助表示赞赏。
答案 0 :(得分:1)
您尚未在实体中包含任何映射信息。您需要使用@OneToMany
和@ManyToOne
,以便Hibernate知道您的实体如何相互关联。