Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Yurben-bit/Sistema-de-Administraci-n-Escolar-Backend/llms.txt
Use this file to discover all available pages before exploring further.
Overview
EduTec Backend uses Spring Data JPA with Hibernate as the ORM (Object-Relational Mapping) provider. The application supports multiple database systems, with MySQL 8.0.19 as the primary production database.The flexible database architecture allows development with H2 (in-memory) while deploying to MySQL, Oracle, MariaDB, or SQL Server in production without code changes.
Supported Databases
The project includes JDBC drivers for multiple database systems:- MySQL
- H2 (In-Memory)
- MariaDB
- Oracle
- Microsoft SQL Server
Version: 8.0.19Status: Primary production databaseConnection URL Pattern:
MySQL 8.0+ requires the
cj package in the driver class name. The older com.mysql.jdbc.Driver is deprecated.JPA Configuration
The application uses Spring Data JPA for database operations:- Spring Data JPA - Repository abstraction layer
- Hibernate Core - JPA implementation
- Spring Transaction Management - Declarative transaction support
- JDBC Connection Pooling - HikariCP (default in Spring Boot 2.x)
Entity Model: User
TheUser entity represents the core authentication and user management table.
Entity Definition
Annotations Explained
@Entity
@Entity
Purpose: Marks this class as a JPA entity that maps to a database tableEffect: Hibernate will manage instances of this class and persist them to the database
@Table(name = 'usuarios')
@Table(name = 'usuarios')
Purpose: Specifies the database table nameDefault: Without this annotation, the table name would be
user (class name in lowercase)Custom Name: Maps to the usuarios table in the databaseUsing a Spanish table name (
usuarios) indicates this may be for a Spanish-speaking user base or legacy database naming conventions.Lombok Annotations
Lombok Annotations
@Data - Generates:
- Getters for all fields
- Setters for all non-final fields
toString()methodequals()andhashCode()methods- Required arguments constructor
These Lombok annotations dramatically reduce boilerplate code. Without them, you would need to manually write ~50 lines of getters, setters, and other methods.
@Id and @GeneratedValue
@Id and @GeneratedValue
@Id - Marks this field as the primary key@GeneratedValue(strategy = GenerationType.IDENTITY):Alternative Strategies:
- Delegates primary key generation to the database
- Uses AUTO_INCREMENT (MySQL/MariaDB) or IDENTITY columns (SQL Server)
- Database generates the ID when inserting new records
AUTO- JPA provider chooses the strategySEQUENCE- Uses database sequences (Oracle, PostgreSQL)TABLE- Uses a separate table to generate IDsUUID- Generates UUIDs (requires custom generator)
@Column Constraints
@Column Constraints
Username Field:
nullable = false: NOT NULL constraint - username is requiredunique = true: UNIQUE constraint - no duplicate usernames
nullable = false: Password is required
Generated Database Schema
Hibernate will generate the following SQL DDL:id: BIGINT (maps from JavaLong)username: VARCHAR(255) (default String length)password: VARCHAR(255)
Hibernate automatically creates an index on the
username column due to the unique = true constraint, optimizing login queries.Hibernate Configuration
The project includes several Hibernate extensions and utilities:Hibernate Core Dependencies
Hibernate Agroal (5.4.30.Final)
Hibernate Agroal (5.4.30.Final)
Purpose: Connection pool integrationAgroal is a modern connection pool that provides:
- Fast connection acquisition
- Leak detection
- Connection validation
- Metrics and monitoring
Hibernate Search (5.11.8.Final)
Hibernate Search (5.11.8.Final)
Purpose: Full-text search capabilities using Apache LuceneUse Cases:
- Search users by name or email
- Autocomplete functionality
- Advanced text queries (fuzzy matching, wildcards)
Hibernate Validator (7.0.1.Final)
Hibernate Validator (7.0.1.Final)
Purpose: Bean validation (JSR 380 implementation)Example Validations:
Hibernate Envers (5.5.0.Final)
Hibernate Envers (5.5.0.Final)
Purpose: Entity auditing and versioningSpring Data Integration:Features:
- Track all changes to entities
- Query historical data
- Audit trail compliance
- Rollback capability
Envers creates shadow audit tables (e.g.,
usuarios_AUD) that store historical versions of each entity, perfect for compliance requirements.Database Configuration
Current configuration inapplication.properties:
Configuration Properties Explained
- spring.jpa.hibernate.ddl-auto
- spring.jpa.show-sql
- Hibernate Dialect
- HikariCP Settings
Controls automatic schema management:
none- No automatic schema operationsvalidate- Validate schema matches entities (safe for production)update- Update schema to match entities (adds columns/tables, never drops)create- Drop and recreate schema on startupcreate-drop- Create on startup, drop on shutdown
Use
validate or none in production with proper database migration tools like Flyway or Liquibase.Data Access Pattern
While not shown in the current codebase, typical Spring Data JPA usage would include:Repository Interface
save(User user)- Insert or updatefindById(Long id)- Find by primary keyfindAll()- Get all usersdeleteById(Long id)- Delete by primary keycount()- Count total users
findByUsername(String username)- Find user by usernameexistsByUsername(String username)- Check if username exists
Spring Data JPA derives the SQL query from the method name. No implementation code needed!
Service Layer Example
Migration Strategy
Development Phase
For development, use Hibernate’s automatic schema generation:Production Deployment
For production, use database migration tools:- Flyway
- Liquibase
Add to Create migrations in Configure:
pom.xml:src/main/resources/db/migration/:Best Practices
Entity Design
-
Always use
@Column(nullable = false)for required fields - Database constraints are the last line of defense -
Add indexes for frequently queried columns:
-
Use appropriate field types:
Longfor IDs (notInteger)LocalDateTimefor timestamps (notDate)BigDecimalfor currency (notdouble)
-
Add timestamps for auditing:
Performance Optimization
-
Enable second-level cache:
-
Use batch inserts:
-
Configure connection pool properly:
- Match pool size to your workload
- Monitor connection usage
- Set appropriate timeouts
Next Steps
- Authentication - Integrate user authentication with database validation
- Architecture - Understand how the repository layer fits into the overall system
- API Reference - Explore endpoints that interact with the database