0

有没有特别好的方法可以做到这一点?我使用 Panache/Hibernate ORM 来扩展 PanacheEntity 以为新表的架构创建映射。一切都使用 Repository 方法按预期工作,我有正确的端点来反映 GET、PUT 等。我目前的问题是我试图有一个完全不同的端点,它只在 Postgresql 函数/存储过程上执行 GET 并返回当你到达那个端点时的那个数据。这是终点——

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;



@Path("/holidays")
@Produces("application/json")
@Consumes("application/json")
public class HolidayResource {

    @Inject
    EntityManager entityManager;

    @GET
    public Holiday[] get() {
        return entityManager.createNamedQuery("Holidays.findAll", Holiday.class)
                .getResultList().toArray(new Holiday[0]);
    }
    
}

这是对象/类 -

import java.sql.Date;
import java.sql.Timestamp;

import javax.persistence.Entity;
import javax.persistence.Id;

import org.hibernate.annotations.NamedNativeQuery;


@Entity
@NamedNativeQuery(name = "Holidays.findAll", query = "SELECT * FROM holidays.usa('NY', 2020, 2020)")
public class Holiday {


    public static enum Authority {
        federal,
        national,
        bank,
        provincial,
        state,
        informal,
        observance,
        shortened_work_day,
        optional,
        de_facto,
        religious,
        extra_work_day,
        municipal
    }

    @Id public long id;
    public Date datestamp;
    public String description;
    public Authority authority;
    public Boolean day_off;
    public Boolean observation_shifted;
    public Timestamp start_time;
    public Timestamp end_time;

}

请注意,我并不是想创建一个表格或任何只是为了显示的东西。这是堆栈跟踪,但我尝试了一些似乎让我陷入困境的事情(例如添加 getter/setter 和其他东西) -

java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: SRCFG00013: No Converter registered for interface java.nio.file.Path
        at io.quarkus.vertx.http.runtime.VertxHttpRecorder.startServerAfterFailedStart(VertxHttpRecorder.java:223)
        at io.quarkus.vertx.http.runtime.devmode.VertxHttpHotReplacementSetup.handleFailedInitialStart(VertxHttpHotReplacementSetup.java:37)
        at io.quarkus.deployment.dev.RuntimeUpdatesProcessor.startupFailed(RuntimeUpdatesProcessor.java:662)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.firstStart(IsolatedDevModeMain.java:137)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:378)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:56)
        at io.quarkus.bootstrap.app.CuratedApplication.runInCl(CuratedApplication.java:127)
        at io.quarkus.bootstrap.app.CuratedApplication.runInAugmentClassLoader(CuratedApplication.java:84)
        at io.quarkus.deployment.dev.DevModeMain.start(DevModeMain.java:144)
        at io.quarkus.deployment.dev.DevModeMain.main(DevModeMain.java:63)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: SRCFG00013: No Converter registered for interface java.nio.file.Path
        at io.quarkus.runtime.configuration.ConfigInstantiator.handleObject(ConfigInstantiator.java:106)
        at io.quarkus.runtime.configuration.ConfigInstantiator.handleObject(ConfigInstantiator.java:57)
        at io.quarkus.vertx.http.runtime.VertxHttpRecorder.startServerAfterFailedStart(VertxHttpRecorder.java:195)
        ... 9 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: SRCFG00013: No Converter registered for interface java.nio.file.Path
        at io.quarkus.runtime.configuration.ConfigInstantiator.handleObject(ConfigInstantiator.java:106)
        at io.quarkus.runtime.configuration.ConfigInstantiator.handleObject(ConfigInstantiator.java:79)
        ... 11 more
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: SRCFG00013: No Converter registered for interface java.nio.file.Path
        at io.quarkus.runtime.configuration.ConfigInstantiator.handleObject(ConfigInstantiator.java:106)
        at io.quarkus.runtime.configuration.ConfigInstantiator.handleObject(ConfigInstantiator.java:79)
        ... 12 more
Caused by: java.lang.IllegalArgumentException: SRCFG00013: No Converter registered for interface java.nio.file.Path
        at io.smallrye.config.SmallRyeConfig.lambda$getConverter$2(SmallRyeConfig.java:292)
        at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705)
        at io.smallrye.config.SmallRyeConfig.getConverter(SmallRyeConfig.java:289)
        at io.quarkus.runtime.configuration.ConfigInstantiator.getConverterFor(ConfigInstantiator.java:121)
        at io.quarkus.runtime.configuration.ConfigInstantiator.getConverterFor(ConfigInstantiator.java:117)
        at io.quarkus.runtime.configuration.ConfigInstantiator.handleObject(ConfigInstantiator.java:91)
        ... 13 more

Postgres 函数/存储过程是根据我在某处找到的 Python 脚本创建的,它会像这样被调用,并反映在@NamedNativeQuery注释中。-

SELECT * from holidays.usa('NY', 2020, 2020);

查询返回的示例 -

datestamp       description                authority      day_off      observation_shifted   start_time   end_time        
[DATE]          [TEXT]                     [ENUM]         [BOOLEAN]    [BOOLEAN]             [TIME]       [TIME]
------------    -----------------------    -----------    ---------    -------------------   ----------   ----------
"2020-01-01"    "New Year's Day"           "federal"       true        false                 "00:00:00"   "24:00:00"
"2020-02-17"    "Family Day"               "provincial"    true        false                 "00:00:00"   "24:00:00

有一个更好的方法吗?我尝试过的一些事情似乎把我带入了错误的圈子。

4

2 回答 2

0

对于SRCFG00013: No Converter registered for interface java.nio.file.Path像我一样登陆这里的未来读者:

我遇到了类似的问题并得到了相同的 SRCFG00013 错误消息,但听起来很愚蠢,解决方案是在日志文件中向上滚动,因为带有有意义消息的真正休眠堆栈跟踪远远高于这个神秘的 SRCFG00013 错误.

于 2021-05-06T08:40:14.477 回答
0

您可以定义一个@NamedStoredProcedure

@NamedStoredProcedureQuery(
    name = "Holidays.findAll", 
    procedureName = "holidays.usa", 
    resultClasses = Holiday.class, 
    parameters = {
            @StoredProcedureParameter(
                name = "city",
                type = String.class,
                mode = ParameterMode.IN
            ),
            @StoredProcedureParameter(
                name = "year",
                type = Integer.class,
                mode = ParameterMode.IN
            ),
            // Additional parameters
            ...
        }
)

@Entity
public class Holiday {
}
List<Holiday> holidays = entityManager
.createNamedStoredProcedureQuery( "Holidays.findAll" )
.setParameter( "city", "NY" )
.setParameter( "year", 2020 )
 ...
.getResultList();

或者您可以通过 entityManager 调用存储过程

StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "holidays.usa", Holiday.class);
query.registerStoredProcedureParameter( "city", String.class, ParameterMode.IN);
query.registerStoredProcedureParameter( "year", Integer.class, ParameterMode.IN);
... // register other parameters

query.setParameter("city", "NY");
query.setParameter("year", 2020);
... // set other parameters
List<Holiday> holidays = query.getResultList();
于 2021-05-01T23:44:13.667 回答