الاستعلامات الأصلية (Native queries)
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
use plain SQL when JPQL cannot express the query.
الموضوعات المخطط لها
@Query(nativeQuery = true)runs real SQL against the database.- Use it for database-specific features (window functions, full-text search) and heavy reports.
- It is not portable and bypasses entity names; refactoring does not update it.
- Default to JPQL or derived queries; native is the exception.
- Pair native queries with projections, not entities, for reports.
تفاصيل المخطط المبدئي
عرض عملي
@Query(value = "select c.name as category, count(*) as total from product p " +
"join category c on c.id = p.category_id group by c.name", nativeQuery = true)
List<CategoryCount> countPerCategory();اختبر فهمك
Should native queries be your default?
أظهر الإجابة
No; use them only when needed.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.