使用springboot数据打开JPA,使用PUT和DELETE操作给出错误:无法将org.apache.openjpa.util.LongId强制转换为java.lang.Long

时间:2017-05-31 13:49:36

标签: spring-boot spring-data-rest openjpa

我正在开发一个使用spring-boot-starter-data-restOpen JPA的应用程序。我使用的是spring-boot版本1.5.3.RELEASE

我要求在Person实体上进行CRUD操作。

@Entity
@Table(name = "PERSON")
public class Person {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "person", fetch = FetchType.EAGER)
public List<Phone> phones;

@Id
@SequenceGenerator(name = "SEQ_GEN", sequenceName = "SEQ_GEN", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_GEN")
@Column(name = "PERSON_ID")
private Long id;

@Column(name = "PERSON_NAME")
private String name;


// Getters and Setters

PersonRepository

@RepositoryRestResource(collectionResourceRel = "person", path = "person")
public interface PersonRepository extends CrudRepository<Person, Long> {

Phone实体

@Entity
@Table(name = "PHONE")
public class Phone {

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "PERSON_ID", nullable = true)
public Person person;

@Id
@SequenceGenerator(name = "PHONE_SEQ_GEN", sequenceName = "PHONE_SEQ_GEN", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PHONE_SEQ_GEN")
@Column(name = "PHONE_ID")
private Long id;

@Column(name = "PHONE_BRAND_NAME")
private String name;

//  Getters and Setters

问题:

  1. 当我发出PUT请求时使用数据休息

    卷曲-X PUT \    http://localhost:8080/person/1 \    -H'缓存控制:无缓存'    -H'内容类型:application / json'\    -d'{    “名字”:“测试人”         }“

    获得以下错误: Cannot cast org.apache.openjpa.util.LongId to java.lang.Long

  2. 以下是我的依赖树:

    testRuntimeClasspath - Runtime classpath of source set 'test'.
    +--- org.springframework.boot:spring-boot-starter-web:1.5.3.RELEASE
    |    +--- org.springframework.boot:spring-boot-starter:1.5.3.RELEASE
    |    |    +--- org.springframework.boot:spring-boot:1.5.3.RELEASE
    |    |    |    +--- org.springframework:spring-core:4.3.8.RELEASE
    |    |    |    \--- org.springframework:spring-context:4.3.8.RELEASE
    |    |    |         +--- org.springframework:spring-aop:4.3.8.RELEASE
    |    |    |         |    +--- org.springframework:spring-beans:4.3.8.RELEASE
    |    |    |         |    |    \--- org.springframework:spring-core:4.3.8.RELEASE
    |    |    |         |    \--- org.springframework:spring-core:4.3.8.RELEASE
    |    |    |         +--- org.springframework:spring-beans:4.3.8.RELEASE (*)
    |    |    |         +--- org.springframework:spring-core:4.3.8.RELEASE
    |    |    |         \--- org.springframework:spring-expression:4.3.8.RELEASE
    |    |    |              \--- org.springframework:spring-core:4.3.8.RELEASE
    |    |    +--- org.springframework.boot:spring-boot-autoconfigure:1.5.3.RELEASE
    |    |    |    \--- org.springframework.boot:spring-boot:1.5.3.RELEASE (*)
    |    |    +--- org.springframework.boot:spring-boot-starter-logging:1.5.3.RELEASE
    |    |    |    +--- ch.qos.logback:logback-classic:1.1.11 -> 1.2.3
    |    |    |    |    +--- ch.qos.logback:logback-core:1.2.3
    |    |    |    |    \--- org.slf4j:slf4j-api:1.7.25
    |    |    |    +--- org.slf4j:jcl-over-slf4j:1.7.25
    |    |    |    |    \--- org.slf4j:slf4j-api:1.7.25
    |    |    |    +--- org.slf4j:jul-to-slf4j:1.7.25
    |    |    |    |    \--- org.slf4j:slf4j-api:1.7.25
    |    |    |    \--- org.slf4j:log4j-over-slf4j:1.7.25
    |    |    |         \--- org.slf4j:slf4j-api:1.7.25
    |    |    +--- org.springframework:spring-core:4.3.8.RELEASE
    |    |    \--- org.yaml:snakeyaml:1.17
    |    +--- org.springframework.boot:spring-boot-starter-tomcat:1.5.3.RELEASE
    |    |    +--- org.apache.tomcat.embed:tomcat-embed-core:8.5.14
    |    |    +--- org.apache.tomcat.embed:tomcat-embed-el:8.5.14
    |    |    \--- org.apache.tomcat.embed:tomcat-embed-websocket:8.5.14
    |    |         \--- org.apache.tomcat.embed:tomcat-embed-core:8.5.14
    |    +--- org.hibernate:hibernate-validator:5.3.5.Final
    |    |    +--- javax.validation:validation-api:1.1.0.Final
    |    |    +--- org.jboss.logging:jboss-logging:3.3.0.Final -> 3.3.1.Final
    |    |    \--- com.fasterxml:classmate:1.3.1 -> 1.3.3
    |    +--- com.fasterxml.jackson.core:jackson-databind:2.8.8
    |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.8.0
    |    |    \--- com.fasterxml.jackson.core:jackson-core:2.8.8
    |    +--- org.springframework:spring-web:4.3.8.RELEASE
    |    |    +--- org.springframework:spring-aop:4.3.8.RELEASE (*)
    |    |    +--- org.springframework:spring-beans:4.3.8.RELEASE (*)
    |    |    +--- org.springframework:spring-context:4.3.8.RELEASE (*)
    |    |    \--- org.springframework:spring-core:4.3.8.RELEASE
    |    \--- org.springframework:spring-webmvc:4.3.8.RELEASE
    |         +--- org.springframework:spring-aop:4.3.8.RELEASE (*)
    |         +--- org.springframework:spring-beans:4.3.8.RELEASE (*)
    |         +--- org.springframework:spring-context:4.3.8.RELEASE (*)
    |         +--- org.springframework:spring-core:4.3.8.RELEASE
    |         +--- org.springframework:spring-expression:4.3.8.RELEASE (*)
    |         \--- org.springframework:spring-web:4.3.8.RELEASE (*)
    +--- io.springfox:springfox-swagger2:2.6.1
    |    +--- io.swagger:swagger-annotations:1.5.10
    |    +--- io.swagger:swagger-models:1.5.10
    |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.4.5 -> 2.8.0
    |    |    +--- org.slf4j:slf4j-api:1.6.3 -> 1.7.25
    |    |    \--- io.swagger:swagger-annotations:1.5.10
    |    +--- io.springfox:springfox-spi:2.6.1
    |    |    \--- io.springfox:springfox-core:2.6.1
    |    |         +--- com.google.guava:guava:18.0
    |    |         +--- com.fasterxml:classmate:1.3.1 -> 1.3.3
    |    |         +--- org.slf4j:slf4j-api:1.7.21 -> 1.7.25
    |    |         +--- org.springframework.plugin:spring-plugin-core:1.2.0.RELEASE
    |    |         |    +--- org.springframework:spring-beans:4.0.9.RELEASE -> 4.3.8.RELEASE (*)
    |    |         |    +--- org.springframework:spring-context:4.0.9.RELEASE -> 4.3.8.RELEASE (*)
    |    |         |    +--- org.springframework:spring-aop:4.0.9.RELEASE -> 4.3.8.RELEASE (*)
    |    |         |    \--- org.slf4j:slf4j-api:1.7.10 -> 1.7.25
    |    |         \--- org.springframework.plugin:spring-plugin-metadata:1.2.0.RELEASE
    |    |              +--- org.springframework.plugin:spring-plugin-core:1.2.0.RELEASE (*)
    |    |              \--- org.slf4j:slf4j-api:1.7.10 -> 1.7.25
    |    +--- io.springfox:springfox-schema:2.6.1
    |    |    +--- io.springfox:springfox-core:2.6.1 (*)
    |    |    \--- io.springfox:springfox-spi:2.6.1 (*)
    |    +--- io.springfox:springfox-swagger-common:2.6.1
    |    |    +--- io.swagger:swagger-annotations:1.5.10
    |    |    +--- io.swagger:swagger-models:1.5.10 (*)
    |    |    +--- io.springfox:springfox-spi:2.6.1 (*)
    |    |    +--- io.springfox:springfox-schema:2.6.1 (*)
    |    |    +--- io.springfox:springfox-spring-web:2.6.1
    |    |    |    +--- com.google.guava:guava:18.0
    |    |    |    +--- com.fasterxml:classmate:1.3.1 -> 1.3.3
    |    |    |    +--- org.slf4j:slf4j-api:1.7.21 -> 1.7.25
    |    |    |    +--- org.springframework.plugin:spring-plugin-core:1.2.0.RELEASE (*)
    |    |    |    +--- org.springframework.plugin:spring-plugin-metadata:1.2.0.RELEASE (*)
    |    |    |    \--- io.springfox:springfox-spi:2.6.1 (*)
    |    |    +--- com.google.guava:guava:18.0
    |    |    +--- com.fasterxml:classmate:1.3.1 -> 1.3.3
    |    |    +--- org.slf4j:slf4j-api:1.7.21 -> 1.7.25
    |    |    +--- org.springframework.plugin:spring-plugin-core:1.2.0.RELEASE (*)
    |    |    \--- org.springframework.plugin:spring-plugin-metadata:1.2.0.RELEASE (*)
    |    +--- io.springfox:springfox-spring-web:2.6.1 (*)
    |    +--- com.google.guava:guava:18.0
    |    +--- com.fasterxml:classmate:1.3.1 -> 1.3.3
    |    +--- org.slf4j:slf4j-api:1.7.21 -> 1.7.25
    |    +--- org.springframework.plugin:spring-plugin-core:1.2.0.RELEASE (*)
    |    +--- org.springframework.plugin:spring-plugin-metadata:1.2.0.RELEASE (*)
    |    \--- org.mapstruct:mapstruct:1.0.0.Final
    +--- io.springfox:springfox-swagger-ui:2.6.1
    |    \--- io.springfox:springfox-spring-web:2.6.1 (*)
    +--- org.slf4j:slf4j-api:1.7.25
    +--- ch.qos.logback:logback-classic:1.2.3 (*)
    +--- ch.qos.logback:logback-core:1.2.3
    +--- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.8.1
    |    +--- com.fasterxml.jackson.core:jackson-core:2.8.1 -> 2.8.8
    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.8.0
    |    +--- com.fasterxml.jackson.core:jackson-databind:2.8.1 -> 2.8.8 (*)
    |    +--- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.8.1 -> 2.8.8
    |    |    +--- com.fasterxml.jackson.core:jackson-core:2.8.8
    |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.8.0
    |    |    \--- com.fasterxml.jackson.core:jackson-databind:2.8.8 (*)
    |    +--- org.codehaus.woodstox:stax2-api:3.1.4
    |    \--- com.fasterxml.woodstox:woodstox-core:5.0.2
    |         \--- org.codehaus.woodstox:stax2-api:3.1.4
    +--- org.springframework.boot:spring-boot-starter-actuator:1.5.3.RELEASE
    |    +--- org.springframework.boot:spring-boot-starter:1.5.3.RELEASE (*)
    |    \--- org.springframework.boot:spring-boot-actuator:1.5.3.RELEASE
    |         +--- org.springframework.boot:spring-boot:1.5.3.RELEASE (*)
    |         +--- org.springframework.boot:spring-boot-autoconfigure:1.5.3.RELEASE (*)
    |         +--- com.fasterxml.jackson.core:jackson-databind:2.8.8 (*)
    |         +--- org.springframework:spring-core:4.3.8.RELEASE
    |         \--- org.springframework:spring-context:4.3.8.RELEASE (*)
    +--- org.apache.openjpa:openjpa-all:2.4.1
    +--- org.flywaydb:flyway-core:3.2.1
    +--- project :common
    |    +--- org.springframework.boot:spring-boot-starter-web:1.5.3.RELEASE (*)
    |    +--- io.springfox:springfox-swagger2:2.6.1 (*)
    |    +--- io.springfox:springfox-swagger-ui:2.6.1 (*)
    |    +--- org.slf4j:slf4j-api:1.7.25
    |    +--- ch.qos.logback:logback-classic:1.2.3 (*)
    |    +--- ch.qos.logback:logback-core:1.2.3
    |    +--- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.8.1 (*)
    |    +--- org.springframework.boot:spring-boot-starter-actuator:1.5.3.RELEASE (*)
    |    +--- org.springframework.boot:spring-boot-starter-data-rest:1.5.3.RELEASE
    |    |    +--- org.springframework.boot:spring-boot-starter:1.5.3.RELEASE (*)
    |    |    +--- org.springframework.boot:spring-boot-starter-web:1.5.3.RELEASE (*)
    |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.8.0
    |    |    +--- com.fasterxml.jackson.core:jackson-databind:2.8.8 (*)
    |    |    \--- org.springframework.data:spring-data-rest-webmvc:2.6.3.RELEASE
    |    |         +--- org.springframework.data:spring-data-rest-core:2.6.3.RELEASE
    |    |         |    +--- org.springframework:spring-tx:4.3.8.RELEASE
    |    |         |    |    +--- org.springframework:spring-beans:4.3.8.RELEASE (*)
    |    |         |    |    \--- org.springframework:spring-core:4.3.8.RELEASE
    |    |         |    +--- org.springframework.hateoas:spring-hateoas:0.23.0.RELEASE
    |    |         |    |    +--- org.springframework:spring-aop:4.3.5.RELEASE -> 4.3.8.RELEASE (*)
    |    |         |    |    +--- org.springframework:spring-beans:4.3.5.RELEASE -> 4.3.8.RELEASE (*)
    |    |         |    |    +--- org.springframework:spring-context:4.3.5.RELEASE -> 4.3.8.RELEASE (*)
    |    |         |    |    +--- org.springframework:spring-core:4.3.5.RELEASE -> 4.3.8.RELEASE
    |    |         |    |    +--- org.springframework:spring-web:4.3.5.RELEASE -> 4.3.8.RELEASE (*)
    |    |         |    |    +--- org.springframework:spring-webmvc:4.3.5.RELEASE -> 4.3.8.RELEASE (*)
    |    |         |    |    \--- org.slf4j:slf4j-api:1.7.22 -> 1.7.25
    |    |         |    +--- org.springframework.data:spring-data-commons:1.13.3.RELEASE
    |    |         |    |    +--- org.springframework:spring-core:4.3.8.RELEASE
    |    |         |    |    +--- org.springframework:spring-beans:4.3.8.RELEASE (*)
    |    |         |    |    +--- org.slf4j:slf4j-api:1.7.24 -> 1.7.25
    |    |         |    |    \--- org.slf4j:jcl-over-slf4j:1.7.24 -> 1.7.25 (*)
    |    |         |    +--- org.springframework.plugin:spring-plugin-core:1.2.0.RELEASE (*)
    |    |         |    +--- org.atteo:evo-inflector:1.2.1
    |    |         |    +--- com.fasterxml.jackson.core:jackson-annotations:2.8.7 -> 2.8.0
    |    |         |    +--- org.slf4j:slf4j-api:1.7.24 -> 1.7.25
    |    |         |    \--- org.slf4j:jcl-over-slf4j:1.7.24 -> 1.7.25 (*)
    |    |         +--- org.springframework:spring-webmvc:4.3.8.RELEASE (*)
    |    |         +--- com.fasterxml.jackson.core:jackson-databind:2.8.7 -> 2.8.8 (*)
    |    |         +--- com.fasterxml.jackson.core:jackson-annotations:2.8.7 -> 2.8.0
    |    |         +--- org.slf4j:slf4j-api:1.7.24 -> 1.7.25
    |    |         \--- org.slf4j:jcl-over-slf4j:1.7.24 -> 1.7.25 (*)
    |    +--- org.springframework.boot:spring-boot-starter-data-jpa:1.5.3.RELEASE
    |    |    +--- org.springframework.boot:spring-boot-starter:1.5.3.RELEASE (*)
    |    |    +--- org.springframework.boot:spring-boot-starter-aop:1.5.3.RELEASE
    |    |    |    +--- org.springframework.boot:spring-boot-starter:1.5.3.RELEASE (*)
    |    |    |    +--- org.springframework:spring-aop:4.3.8.RELEASE (*)
    |    |    |    \--- org.aspectj:aspectjweaver:1.8.10
    |    |    +--- org.springframework.boot:spring-boot-starter-jdbc:1.5.3.RELEASE
    |    |    |    +--- org.springframework.boot:spring-boot-starter:1.5.3.RELEASE (*)
    |    |    |    +--- org.apache.tomcat:tomcat-jdbc:8.5.14
    |    |    |    |    \--- org.apache.tomcat:tomcat-juli:8.5.14
    |    |    |    \--- org.springframework:spring-jdbc:4.3.8.RELEASE
    |    |    |         +--- org.springframework:spring-beans:4.3.8.RELEASE (*)
    |    |    |         +--- org.springframework:spring-core:4.3.8.RELEASE
    |    |    |         \--- org.springframework:spring-tx:4.3.8.RELEASE (*)
    |    |    +--- javax.transaction:javax.transaction-api:1.2
    |    |    +--- org.springframework.data:spring-data-jpa:1.11.3.RELEASE
    |    |    |    +--- org.springframework.data:spring-data-commons:1.13.3.RELEASE (*)
    |    |    |    +--- org.springframework:spring-orm:4.3.8.RELEASE
    |    |    |    |    +--- org.springframework:spring-beans:4.3.8.RELEASE (*)
    |    |    |    |    +--- org.springframework:spring-core:4.3.8.RELEASE
    |    |    |    |    +--- org.springframework:spring-jdbc:4.3.8.RELEASE (*)
    |    |    |    |    \--- org.springframework:spring-tx:4.3.8.RELEASE (*)
    |    |    |    +--- org.springframework:spring-context:4.3.8.RELEASE (*)
    |    |    |    +--- org.springframework:spring-aop:4.3.8.RELEASE (*)
    |    |    |    +--- org.springframework:spring-tx:4.3.8.RELEASE (*)
    |    |    |    +--- org.springframework:spring-beans:4.3.8.RELEASE (*)
    |    |    |    +--- org.springframework:spring-core:4.3.8.RELEASE
    |    |    |    +--- org.slf4j:slf4j-api:1.7.24 -> 1.7.25
    |    |    |    \--- org.slf4j:jcl-over-slf4j:1.7.24 -> 1.7.25 (*)
    |    |    \--- org.springframework:spring-aspects:4.3.8.RELEASE
    |    |         \--- org.aspectj:aspectjweaver:1.8.9 -> 1.8.10
    |    +--- org.apache.openjpa:openjpa-all:2.4.1
    |    +--- joda-time:joda-time:2.9.9
    |    +--- org.aspectj:aspectjweaver:1.8.8 -> 1.8.10
    |    +--- com.fasterxml.jackson.core:jackson-databind:2.8.8 (*)
    |    +--- org.apache.commons:commons-lang3:3.5
    |    \--- org.postgresql:postgresql:9.4.1208 -> 9.4.1212.jre7
    +--- junit:junit:4.11
    |    \--- org.hamcrest:hamcrest-core:1.3
    +--- org.powermock:powermock-module-junit4:1.6.6
    |    +--- junit:junit:4.12 -> 4.11 (*)
    |    \--- org.powermock:powermock-module-junit4-common:1.6.6
    |         +--- junit:junit:4.12 -> 4.11 (*)
    |         +--- org.powermock:powermock-core:1.6.6
    |         |    +--- org.powermock:powermock-reflect:1.6.6
    |         |    |    \--- org.objenesis:objenesis:2.4
    |         |    \--- org.javassist:javassist:3.21.0-GA
    |         \--- org.powermock:powermock-reflect:1.6.6 (*)
    +--- org.powermock:powermock-api-mockito:1.6.6
    |    +--- org.mockito:mockito-core:1.10.19
    |    |    +--- org.hamcrest:hamcrest-core:1.1 -> 1.3
    |    |    \--- org.objenesis:objenesis:2.1 -> 2.4
    |    +--- org.hamcrest:hamcrest-core:1.3
    |    \--- org.powermock:powermock-api-mockito-common:1.6.6
    |         +--- org.hamcrest:hamcrest-core:1.3
    |         \--- org.powermock:powermock-api-support:1.6.6
    |              +--- org.powermock:powermock-core:1.6.6 (*)
    |              \--- org.powermock:powermock-reflect:1.6.6 (*)
    \--- org.springframework:spring-test:4.1.6.RELEASE
         \--- org.springframework:spring-core:4.1.6.RELEASE -> 4.3.8.RELEASE
    

0 个答案:

没有答案