【发布时间】:2014-07-31 04:00:44
【问题描述】:
我有一个名为 StockLevel 的实体和另一个名为 Version 的实体,它们的关系如下:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "version", nullable = false, referencedColumnName = "pk")
private VersionModel version;
现在我想通过 Spring-Data-REST 创建一个新的 StockLevel,所以我向 http://somedomain.com:8111/storefront/rest/stock_level/ 发出以下 POST 请求
{
"uid" : "mynewuidForStockLevel",
"version" :
{
"rel" : "version",
"href":"http://localhost:8111/storefront/rest/version/3378719354003680"
}
}
这是我的Version 模型:
@Cacheable
@Entity(name = VersionModel.NAME)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name = VersionModel.NAME,
uniqueConstraints = { @UniqueConstraint(columnNames = { "pk" }) },
indexes = { @Index(columnList = "id")})
public class VersionModel extends AbstractEntityModel {
public static final String NAME = "version";
}
但是我在 Fasterxml Jackson 中得到一个空指针异常:
Caused by: java.lang.NullPointerException
at java.net.URI$Parser.parse(URI.java:3023)
at java.net.URI.<init>(URI.java:595)
at java.net.URI.create(URI.java:857)
at org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module$UriStringDeserializer.deserialize(PersistentEntityJackson2Module.java:359)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:525)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:99)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:242)
我做错了什么?
【问题讨论】:
-
不应该是
"version": "http://localhost:8111/storefront/rest/version/3378719354003680"吗? -
你的 VersionModel 实体是什么样子的?
-
这是版本模型:
-
@Cacheable @Entity(name = VersionModel.NAME) @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @Table(name = VersionModel.NAME, uniqueConstraints = { @UniqueConstraint(columnNames = { "pk" } ) }, 索引 = { @Index(columnList = "id")}) 公共类 VersionModel 扩展 AbstractEntityModel { public static final String NAME = "version"; }
-
这个网站太垃圾了!!!!!!我无法在回复中发布代码 - 我添加了 4 个空格,但它仍然没有显示为代码。
标签: spring rest spring-data spring-data-jpa spring-data-rest