Embedded collection-like entity

Hello,

I’m trying to create a database model, but I have issues, because it seems every route CUBA Supports has some fatal drawbacks, making it really difficult to come up with a complete solution.

I have a class, that every Entity of the project inherits from, called StandardClientEntity. I need to extend this in order to get some functionality I’d not have otherwise.

On top of that, I want some entities to have localized attributes, like names, descriptions, whatever.

The current solution is as follows:

We have the StandardClientEntity, which is the base of every class (not directly in every case), annotated with @MappedSuperclass

We have a DictionaryBaseEntity (inherited from SCE). Every entity that is inherited from this can have localized attributes. This Entity has a ManyToMany relationship (perhaps a OneToMany would be enough, but after trial and error this is what I was left with) to a Dictionary entity. The inheritance in this case is done with the JOINED_TABLES method, which is needed because we don’t want to trash our DICTIONARY_BASE_ENTITY table with all the localized entities, but we do need a separate table, so there can be a reverse column in the DICTIONARY table.

The Dictionary entity has all the localized information, with columns to store the name of the localized attribute, the language and the actual value. I wrote some functions so that it works great for the localized attributes of inheriting classes.

The problem with this model is the fact that we want some fields (mostly simple String or Int) in the localized entities that are unique. To achive this, CUBA (wisely) creates a unique index for this field for cases where DELETE_TS is null (that’s pretty clever), but since the DictionaryBaseEntity is inherited with JOINED_TABLES method the actual entity table doesn’t have a DELETE_TS column (the DictionaryBaseEntity does), so the SQL script fails. This could be solved by rewriting the SQL script, but we don’t want to do this every time, and also we introduce unwanted artifacts into the system.


After looking into the features offered by JPA, I stumbled upon Embedding the dictionaries, which could possibly solve all my problems, but CUBA doesn’t seem to support CollectionEmbedding yet.

Another solution that came up would have to be the SecondaryTable, but that doesn’t seem to work either, since I can’t map a non-basic attribute to the secondary table.

Any idea to achive a better solution, possibly without unwanted drawbacks that could bite me in the a$$ later?

Thanks in advance,
László Stahorszki

Hi László,

You can find some recommendations on creating unique constraints for soft deleted entities with JOINED inheritance in this topic.