# Kiến thức cơ bản về Doctrine ORM (Symfony) > Entities, annotations, EntityManager, repositories, DQL, QueryBuilder, relationships - 25 câu hỏi phỏng vấn - Junior - [Câu hỏi phỏng vấn: Symfony](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van.md) ## 1. Doctrine ORM trong ngữ cảnh của Symfony là gì? **Câu trả lời** Doctrine ORM là một Object-Relational Mapper cho phép thao tác dữ liệu cơ sở dữ liệu thông qua các đối tượng PHP. Nó trừu tượng hóa các truy vấn SQL bằng cách cung cấp một lớp đối tượng, giúp mã dễ bảo trì hơn và có thể di chuyển giữa các hệ quản trị cơ sở dữ liệu khác nhau. Đây là ORM mặc định được khuyến nghị với Symfony. ## 2. Attribute PHP 8 nào nên được dùng để khai báo một class là entity của Doctrine? **Câu trả lời** Attribute #[ORM\Entity] được dùng để báo cho Doctrine biết rằng một class PHP là một entity được ánh xạ tới một bảng cơ sở dữ liệu. Attribute này thay thế các annotations dựa trên comment và là một phần của namespace Doctrine\ORM\Mapping. Nó có thể được kết hợp với repositoryClass để chỉ định một repository tùy chỉnh. ## 3. Làm thế nào để định nghĩa một cột tự động tăng làm primary key trong một entity Doctrine? **Câu trả lời** Để định nghĩa một primary key tự động tăng, cần kết hợp hai attributes: #[ORM\Id] để đánh dấu thuộc tính là định danh, và #[ORM\GeneratedValue] để chỉ ra rằng giá trị sẽ được cơ sở dữ liệu tạo tự động. Chiến lược mặc định là AUTO, sẽ chọn phương pháp phù hợp tùy theo DBMS. ## Còn 22 câu hỏi nữa - Sự khác biệt giữa persist() và flush() trong EntityManager là gì? - Attribute nào nên được dùng để ánh xạ một thuộc tính string tới một cột VARCHAR trong Doctrine? Đăng ký miễn phí: https://sharpskill.dev/vi/login ## Các chủ đề phỏng vấn Symfony khác - [PHP Hiện Đại (8.1+)](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/php-modern-features.md): 20 câu hỏi, Junior - [Kiến thức cơ bản về Symfony](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/symfony-basics.md): 25 câu hỏi, Junior - [Routing & Controllers](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/routing-controllers.md): 20 câu hỏi, Junior - [Twig & Templates](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/twig-templates.md): 20 câu hỏi, Junior - [Biểu mẫu Symfony](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/forms.md): 22 câu hỏi, Junior - [Xác thực dữ liệu](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/validation.md): 18 câu hỏi, Junior - [Dependency Injection & Services](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/dependency-injection.md): 24 câu hỏi, Mid-Level - [Security & Authentication](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/security-authentication.md): 26 câu hỏi, Mid-Level - [Doctrine Nâng cao](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/doctrine-advanced.md): 24 câu hỏi, Mid-Level - [API Platform](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/api-platform.md): 22 câu hỏi, Mid-Level - [Serializer Component](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/serializer.md): 20 câu hỏi, Mid-Level - [Events & Event Subscribers](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/events-subscribers.md): 20 câu hỏi, Mid-Level - [Console & Commands](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/console-commands.md): 18 câu hỏi, Mid-Level - [Messenger Component](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/messenger.md): 22 câu hỏi, Mid-Level - [HTTP Client](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/http-client.md): 18 câu hỏi, Mid-Level - [Cache & Hiệu năng](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/cache.md): 20 câu hỏi, Mid-Level - [Workflow Component](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/workflow.md): 18 câu hỏi, Mid-Level - [Testing Symfony](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/testing.md): 22 câu hỏi, Mid-Level - [Mailer Component](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/mailer.md): 16 câu hỏi, Mid-Level - [Bản dịch & i18n](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/translations.md): 16 câu hỏi, Mid-Level - [EasyAdmin Bundle](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/easyadmin.md): 18 câu hỏi, Mid-Level - [Kiến trúc Symfony](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/architecture-patterns.md): 24 câu hỏi, Senior - [Hiệu năng & Tối ưu hóa](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/performance-optimization.md): 22 câu hỏi, Senior - [Bảo mật nâng cao](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/security-advanced.md): 22 câu hỏi, Senior - [Custom Bundle](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/custom-bundles.md): 20 câu hỏi, Senior - [Microservices với Symfony](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/microservices.md): 22 câu hỏi, Senior - [Real-time & WebSockets](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/real-time.md): 18 câu hỏi, Senior - [Deployment & DevOps](https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/deployment-devops.md): 20 câu hỏi, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/vi/technologies/symfony/cau-hoi-phong-van/doctrine-orm-basics