我正在尝试创建一个使用 Hibernate Panache 和 Rest 的项目,类似于https://github.com/quarkusio/quarkus-quickstarts/tree/master/hibernate-orm-panache-resteasy上的快速入门。
当我尝试@Post
扩展实体时PanacheEntity
,如下所示,我收到以下错误:
javax.ws.rs.ProcessingException:RESTEASY008200:JSON 绑定反序列化错误:无法创建实例
实体
@Entity
@Cacheable
class Trade extends PanacheEntity {
@Column(length = 40, unique = true)
String name;
}
休息资源
import javax.enterprise.context.ApplicationScoped;
import javax.transaction.Transactional;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
@Path("/trades")
@ApplicationScoped
@Produces("application/json")
@Consumes("application/json")
public class TradeReporterResource {
@POST
@Transactional
public Response add(Trade trade) {
System.out.println("begin");
//t.closePrice = trade.closePrice;
System.out.println("persisting");
trade.persist();
System.out.println("persisted");
return Response.ok(trade).build();
}
}
Pom 依赖项
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${quarkus.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>
</dependencies>
Penache 似乎有问题
当我extends PanacheEntity
从Trade
实体中删除时,至少我可以成功发布。