أهلا بكم،
لا أعرف ما إذا كان هذا قد صدر بالفعل ، لأنني لم أجد أي شيء. إذا كان الأمر كذلك ، أنا آسف لإزعاجكم يا رفاق.
لاحظنا في فريقنا سلوكًا غريبًا في الموقف التالي.
يبدو JDBI لدينا
public interface DeviceRepository
{
@RegisterBeanMapper(DeviceRowMapper.class)
@SqlQuery(
"SELECT * FROM myDeviceTable " +
"WHERE name = :propertyEight " +
" AND devicePropertyOne = :propertyOne " +
" AND devicePropertyTwo = :propertyTwo " +
" AND devicePropertyThree =: propertyThree " +
" AND devicePropertyFour =: propertyFour"
" AND devicePropertyFive =: propertyFive"
" AND devicePropertySix =: propertySix"
" AND devicePropertySeven =: propertySeven"
")
List<Device> findAllCurrentWith(
<strong i="9">@Bind</strong> String propertypropertyOneTwo,
<strong i="10">@Bind</strong> String propertypropertyThreeTwo,
<strong i="11">@Bind</strong> String propertyFour,
<strong i="12">@BindBean</strong> DeviceBean deviceBean
);
}
ويبدو أن الفصل DeviceBean
يشبه شيئًا ما
<strong i="17">@Data</strong>
public final class DeviceRequestDto
{
private String propertyTwo;
private String propertyFive;
private String propertySix;
private String propertySeven;
private String propertyEight;
}
كل شيء يعمل بشكل جيد على جهازي عند اختباره وفي خط أنابيبنا مرت الاختبارات بالكامل كما كانت جيدة.
ولكن هنا تكمن المشكلة ، في أحد أعضاء فريقنا ، لم يتم تنفيذ الاختبار أو بشكل أكثر تحديدًا جمل SQL منذ طرح استثناء من الارتباطات .
2020-11-10 10:54:51,542 [http-nio-8081-exec-4] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [/device] threw exception [Request processing failed; nested exception is org.jdbi.v3.core.statement.UnableToCreateStatementException: Missing named parameter 'propertyOne' in binding:{positional:{0:propertyOne,1:propertyThree,2:propertyFour}, named:{}, finder:[{lazy bean property arguments "DeviceBean(...)"}]} [statement:SELECT * FROM myDeviceTable WHERE name = :customerNumber AND devicePropertyOne = :propertyOne AND devicePropertyTwo = :propertyTwo AND devicePropertyThree =: propertyThree AND devicePropertyFour =: propertyFour", arguments:{positional:{0:propertyOne,1:propertyThree,2:propertyFour}, named:{}, finder:[{lazy bean property arguments "DeviceBean(...)"}]}]] with root cause
org.jdbi.v3.core.statement.UnableToCreateStatementException: Missing named parameter 'propertyOne' in binding:{positional:{0:propertyOne,1:propertyThree,2:propertyFour}, named:{}, finder:[{lazy bean property arguments "DeviceBean(...)"}]} [statement:SELECT * FROM myDeviceTable WHERE name = :customerNumber AND devicePropertyOne = :propertyOne AND devicePropertyTwo = :propertyTwo AND devicePropertyThree =: propertyThree AND devicePropertyFour =: propertyFour", arguments:{positional:{0:propertyOne,1:propertyThree,2:propertyFour}, named:{}, finder:[{lazy bean property arguments "DeviceBean(...)"}]}]
at org.jdbi.v3.core.statement.ArgumentBinder.missingNamedParameter(ArgumentBinder.java:147)
لذلك كانت الغريزة الأولى هي ربط معلمات sql بالإضافة إلى التعليق التوضيحي @Bind
.
<strong i="30">@Bind</strong> String propertyOne
<strong i="33">@Bind</strong> String("propertyOne") propertyOne
.ثم اختفى الاستثناء الموجود على جهاز زملائي في العمل. لست متأكدًا تمامًا مما إذا كانت هذه المشكلة من جانبنا ، ولكن كان من الغريب أن أراها تمر على جهازي وخط الأنابيب ، ولكن من فرع رئيسي جديد تم تنفيذه على جهاز زملائي في العمل.
أردت فقط أن أخبرك إذا كان هناك أي تحسن ممكن بأي حال من الأحوال.
استخدام @Bind
بدون تحديد اسم العمود يعمل فقط إذا قمت بتمكين خيار مترجم يقوم بكتابة اسم المعلمة إلى ملف الفئة ، حيث يمكن لـ Jdbi قراءته.
يبدو أن زميلك بحاجة إلى تشغيل هذا. يرجى قراءة هنا: http://jdbi.org/#_compiling_with_parameter_names
لاحظ أيضًا أن التعليق التوضيحي @Bind
يصبح اختياريًا عند استخدام خيار المترجم -parameters
.
حسنًا ، شكرًا لك على توضيح هذا qualidafial .