Accessing Base Project Entities (User Table) from an Add-on Project

Hi Team,
I’m working with a Jmix add-on architecture:

  • Base project containing User entity
  • Add-on projects need to access base entities (e.g., fetch first_name , last_name from User )

Specific questions :

  1. Standard way to access base entities from add-ons?
  2. Correct approach for cross-module entity access?
  3. Special considerations needed?

Environment : Jmix version 1.7.1

Looking for best practices or code examples. Thanks!

Hi Team,

Just following up on this thread to check if there are any updates or guidance on the recommended approach for accessing base entities from Jmix add-ons.

Would appreciate any insights, best practices, or references when you get a chance.

Any Answer???

Hi,
You can utilize “inversion of control” programming pattern for your purpose.
That is, add-on shouldn’t depend on User entity. Instead, both add-on and target project should depend on other abstraction - on the interface that contains necessary methods.

  1. Create an interface in the add-on project, that should be implemented by User entity in any project working with this add-on. It should contain all necessary methods: getFirstName(), getLastName() and others. E.g. “AddonUser”.
  2. Implement this interface by the User entity in your base project.
  3. Use interface in the add-on where you need to access certain attributes of users. Cast types to this interface where necessary.

Standard Approach: Use interface-based inversion of control:

// Add-on defines interface
public interface AddonUser {
String getFirstName();
String getLastName();
}

// Base project implements it
@Entity
public class User implements AddonUser {
// Existing getters satisfy interface
}

What if you want optional add-ons? :x: This interface approach won’t work because your base project won’t compile without the add-on dependency.

Then you need to define some small mandatory core add-on, which is going to be included to every project.
It may define this interface and optionally some other common definitions.

Like jmix-core dependency which is present in every Jmix project.