Я пытаюсь перенести небольшой проект на собственную сборку. В Win10 я могу собрать exe-файл без ошибок, приложение запускается, и теперь я могу вставить его с помощью ctx.insertInto(), но у меня есть множество ctx.newRecord() с ошибкой «Не удалось создать новую запись».
2024-05-26T23:43:31.700+02:00 ERROR 29568 --- [SmartScrumPokerBackendNativeApplication] [boundChannel-10] .WebSocketAnnotationMethodMessageHandler : Unhandled exception from message handler method
java.lang.IllegalStateException: Could not construct new record
at org.jooq.impl.Tools.recordFactory(Tools.java:1538) ~[na:na]
at org.jooq.impl.Tools.newRecord(Tools.java:1377) ~[na:na]
at org.jooq.impl.DefaultDSLContext.newRecord(DefaultDSLContext.java:4844) ~[smart_scrum_poker_backend_native.exe:na]
at org.kbalazs.smart_scrum_poker_backend_native.socket_domain.account_module.repositories.InsecureUserSessionsRepository.create(InsecureUserSessionsRepository.java:22) ~[smart_scrum_poker_backend_native.exe:na]
at [email protected]/java.lang.reflect.Method.invoke(Method.java:580) ~[smart_scrum_poker_backend_native.exe:na]
Этот код не работает в собственном коде, но отлично работает в JVM:
InsecureUserRecord insecureUserRecord = getDSLContext().newRecord(insecureUserTable, insecureUser);
insecureUserRecord.store();
Это может быть как-то связано с проблемой собственного отражения, и, возможно, мне следует как-то перечислить сгенерированные файлы в ReflectionConfigurationFiles, и я пытаюсь найти для этого пример.
Я был бы очень рад подсказке или примеру кода. (Спасибо за быстрый ответ, Лукас!)
RegisterReflectionForBinding
— решение проблемы отражения. Это может быть формат файла на основе классов или JSON. Я думаю, что JSON легко сгенерировать во время сборки со списком папок.
Решение на основе классов:
package org.kbalazs.smart_scrum_poker_backend_native.config;
import org.kbalazs.smart_scrum_poker_backend_native.db.tables.records.InsecureUserRecord;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.annotation.RegisterReflectionForBinding;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportRuntimeHints;
import static org.springframework.aot.hint.MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS;
import static org.springframework.aot.hint.MemberCategory.INVOKE_PUBLIC_METHODS;
import static org.springframework.aot.hint.MemberCategory.PUBLIC_FIELDS;
@Configuration
@RegisterReflectionForBinding({
InsecureUserRecord.class,
})
@ImportRuntimeHints(ReflectionConfiguration.AppRuntimeHintsRegistrar.class)
public class ReflectionConfiguration
{
public static class AppRuntimeHintsRegistrar implements RuntimeHintsRegistrar
{
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader)
{
hints.reflection()
.registerType(InsecureUserRecord.class, PUBLIC_FIELDS, INVOKE_PUBLIC_METHODS, INVOKE_PUBLIC_CONSTRUCTORS)
;
}
}
}
Пользователи описали свои обходные пути здесь: github.com/jOOQ/jOOQ/issues/8779. Проблема в том, что для создания экземпляров подобных записей используется отражение, но я недостаточно хорошо знаю нативный код, чтобы сказать вам, где именно настраивать ваши конфигурации...