What are the Differences Between Non-Persistable and Persistable Entity in Mendix?

In the world of Mendix, a leading low-code application development platform, entities play a crucial role in how data is structured and managed within applications. Entities in Mendix can be classified into two main types: non-persistable and persistable entities. Understanding the differences between these two types is vital for developers to effectively manage data and optimize application performance. This article explores the characteristics, use cases, and key differences between non-persistable and persistable entities in Mendix.
What is Persistable Entity?
Persistable entities in Mendix are designed to store data that needs to be saved in the database. They represent the core data model of an application and are crucial for maintaining long-term data storage. Here are some characteristics and use cases of persistable entities:
- Database Storage: Persistable entities are stored in the Mendix database, meaning their data is saved even after the application is closed or restarted.
- Data Integrity and Consistency: These entities help maintain data integrity and consistency, as they are managed by the database with ACID (Atomicity, Consistency, Isolation, Durability) properties.
- Use Cases: Persistable entities are ideal for data that must be retained over time, such as user information, transaction records, and product catalogs.
Characteristics of Persistable Entity
- Long-Term Storage: Designed for data that requires long-term storage and retrieval. They are automatically saved to the database when created or modified.
- Security: Benefit from database-level security measures, ensuring that data is protected against unauthorized access.
- Data Relationships: Can establish relationships with other persistable entities, enabling complex data models and queries.
- Performance Considerations: While they provide robust data management, operations involving persistable entities may be slower due to database interactions, especially with large datasets.
What is Non-Persistable Entity?
Non-persistable entities, also known as transient entities, are used for temporary data storage that does not need to be saved in the database. They are typically used to manage data within a session or process. Here are some characteristics and use cases of non-persistable entities:
- Temporary Data: Non-persistable entities hold data temporarily, which is discarded when the session ends or the application is closed.
- Use Cases: Ideal for scenarios where data is needed only during a single user session or for temporary calculations, such as form inputs, search filters, or session-specific data.
Characteristics of Non-Persistable Entity
- In-Memory Storage: Data is stored in memory rather than the database, allowing for faster read and write operations.
- No Database Overhead: Since they are not stored in the database, non-persistable entities do not incur the overhead associated with database transactions.
- Session-Specific: Data is specific to a user session and is lost when the session ends, making them unsuitable for long-term data storage.
- Performance Benefits: Ideal for improving performance in scenarios where data persistence is not required, as they eliminate the need for database interactions.
Key Differences Between Non-Persistable and Persistable Entity
- Data Storage:
- Persistable Entities: Data is stored in the Mendix database, ensuring long-term persistence and availability.
- Non-Persistable Entities: Data is stored in memory and is temporary, disappearing after the session ends.
- Use Cases:
- Persistable Entities: Suitable for data that needs to be retained and accessed over time, such as customer records and order details.
- Non-Persistable Entities: Best for temporary data needs, like form inputs or calculations that do not require saving.
- Performance Considerations:
- Persistable Entities: Involve database interactions, which can impact performance, especially with large datasets.
- Non-Persistable Entities: Provide faster performance for temporary data operations, as they do not involve database access.
- Data Relationships:
- Persistable Entities: Can establish complex relationships with other entities, supporting advanced data modeling.
- Non-Persistable Entities: Typically used in isolation or with simple associations to persistable entities.
- Security:
- Persistable Entities: Benefit from database security measures, ensuring data protection.
- Non-Persistable Entities: Require careful handling to ensure data security, as they are not protected by database-level security.
Conclusion
Understanding the differences between non-persistable and persistable entities in Mendix is crucial for developers aiming to build efficient and effective applications. Persistable entities are essential for managing long-term data storage and ensuring data integrity, while non-persistable entities offer performance benefits for temporary data handling. By leveraging the strengths of each entity type, developers can optimize their applications for both performance and functionality, ensuring they meet the needs of users and businesses alike. Whether you are building a data-intensive application or a lightweight, session-based tool, choosing the right entity type is a key step in successful Mendix development.
