JPA Inspired ORM from SQLite to PostgreSQL
Changing a customer's name should not require remembering which DAO to call after every assignment. Loading twenty orders should not accidentally fetch each customer's entire history. Those are the kinds of problems that appear once an application grows beyond a few independent tables. What is Codename One? Codename One is an open-source framework for building native iOS, Android, desktop, and…
A new managed session feature in an ORM framework inspired by JPA simplifies working with databases in applications. Instead of remembering which DAO to call after every assignment, application code maintains relationships directly within the model. Loading data is streamlined, as loading twenty orders will no longer fetch each customer's entire history.
Developers using the framework, Codename One, can build native apps for iOS, Android, desktop, and web from a single Java or Kotlin codebase. The ORM adds a managed session that tracks entities involved in a unit of work, detects changes, and coordinates persistence. Relationships are now an integral part of the model, with both client and backend using the same mapping annotations.
The framework supports SQLite, PostgreSQL, MySQL, and MariaDB databases. A customer and their orders are modeled using separate Java source files. The Customer class contains an id, version, name, and a list of orders. The Order class has an id, a Customer reference, and a totalCents value. The relationship between the two entities is established using mappedBy and OneToMany annotations.
To commit changes, the application code initiates a transaction, creates new entities, sets their properties, and adds them to the appropriate list. After committing the transaction, the changes are persisted in the database. The session, which belongs to a single thread and unit of work, manages the object graph without runtime reflection or proxy generation. This results in improved performance and easier code maintenance.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.