JMix is generating code which is not running ( proove attached )

Jmix version: 2.3.0
Jmix Studio plugin version: 2.3.NIGHTLY1356-241
IntelliJ version: IntelliJ IDEA 2024.1.4 (Ultimate Edition)

I did create a new Project.

I did Generate Model from Database.

Attached you find the source
Bio4_cleaned.zip (116.8 KB)

When I go to http://localhost:8080

The following error is thrown

2024-07-12T17:42:42.261+02:00 ERROR 8056 --- [nio-8080-exec-2] eclipselink.logging.all                  : Exception [EclipseLink-0] (Eclipse Persistence Services - 4.0.2-3-jmix.v202404051618): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------

Exception [EclipseLink-48] (Eclipse Persistence Services - 4.0.2-3-jmix.v202404051618): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [tObjects.objIdCollection].  Only one may be defined as writable, all others must be specified read-only.
Mapping: org.eclipse.persistence.mappings.ManyToOneMapping[tlkpcsObjAdd10]
Descriptor: RelationalDescriptor(com.company.bio4.entity.TObject --> [DatabaseTable(tObjects)])

What is the real causa of this error ?

If you create a new project without the entity TlkpcsObjAdd10, the project is working !

Best regards

Felix

Hi, Felix

The exception caused by tObjects.objIdCollection column in your database schema. It included into two foreign keys, so the two reference attributes of TObject entity has this column as a @JoinColumn. EclipseLink doesn’t support such cases as we see from error message:

Exception Description: Multiple writable mappings exist for the field [tObjects.objIdCollection].  Only one may be defined as writable, all others must be specified read-only.

We need some time to investigate this specific case and how it can be handled in JPA. Will come back soon with updates.

Hello Felix,

As I can see from the project, TObject has composite key foreign references to TlkpcsObjAdd1 (through objAddLkpCs1 and objIdCollection columns) and to TlkpcsObjAdd10 (through objIdCollection and objAddLkpCs10 columns).

Thus, a change of reference to tlkpcsObjAdd1 will break part of reference to tlkpcsObjAdd10 and vice versa (because objIdCollection occurs in both foreign keys). EclipseLink warns about this situation in exception.

Unfortunately, I cannot see how such model can reliably work in JPA, maybe I miss something?

Could you please describe the initial database scheme by which this model has been generated? How this scheme suppose to work?
How these fields (objAddLkpCs1, objIdCollection and objAddLkpCs10) were planned to be filled in during the application workflow?

Regards,
Dmitry

Hello Dmitry

This is an old database for collecting objects for a museum.

There are thousands of objects collected by the same collector, determined by the same people found on the same places.

But these objects might be in total different collections. There are stones from the geology and animals from the vertebrata.

All these objects are described and classified on different kinds. An animal has a gender. The stone has no gender.

An animal will move, so his place where someone found it is not so relevant as a stone where the scientist would like to know exactly the height and the exposure of the place where this stone was found.

This did lead to collection specific codings.

Code 1 in the collection vertebrata is the gender. ( male / female / na )
Code 1 in the collection geology is the exposure of this stone ( south / easth / north / west / none )

So one object is added once to a collection and based on this selection the coding is selected.

And it is true, if this stone becomes an animal and changes the collection from geology to vertebrata, all codings are no more valid …

It is a real world working database from VB Times with MS SQL and it is working.

In the database I did enter a rat and a stone each with the code 1 in the LkpCs1 but different Collection therefore different meaning.

How to proceed ?

Regards

Felix

Hello Felix,

Thank you for clarification.

It is better to rework db structure to make it more suitable for JPA. At the very least you need to get rid of such foreign key property collision. Maybe splitting TObject to TGeologyObject and TVertebrataObject using single table inheritance strategy and dividing conflicting references to different Entities will work. Maybe another approach will be better depending on all other tasks and conditions of the project.

Regards,
Dmitry

Hello Dmitry

To rework the db structure is no option.

There are not limited collections with not limited codes.

So JMix is not able to handle this simple case ? Is it not possible to have a remark for this limitation ?

Regards
Felix

Hi,
Exception [EclipseLink-48] (Eclipse Persistence Services - 4.0.2-3-jmix.v202404051618)
Jmix uses EclipseLink, not producing it. Maybe you can ask on their forums.
I doubt that Hibernate would work here either.

Modern database applications are based on “entities” rather than “tables”. I think that your database was designed for the previous generation of software tools and that such tools would cast a direct SQL query to the database, and then maybe loop through the result with some IF-THEN based on the implicit logic needed to process it.

So, what to do?
You can either start doing it the old way, Jmix enables you to cast an SQL query, but you will have to do a lot by hand.
Or maybe, give EclipseLink what it wants, construct some views in the database and read them …
Maybe you can work with DTOs - read the data and put them into DTO as desired, and then display that DTO in a grid.

Kind regards,
Mladen

Hi @gaslov

As the problems seems to exist because

Exception Description: Multiple writable mappings exist for the field [tObjects.objIdCollection].  Only one may be defined as writable, all others must be specified read-only.

How to define others must be specified read-only. ? The application does not need to write this objIdCollection ( as the collection is once defined and will never change ). So I am happy with the read-only attribute which would follow the JPA ideology :wink: But I don’t know how to set it to read-only ?

This would solve my problem !

Regards
Felix