Custom datatypes in Jmix 2.0

Starting migrating (custom/organization) add-ons to prepare migration of the first application I’m experiencing first problems.

The following add-on setup worked until Jmix version 1.5.3 - but does not in Jmix 2.0.1.

There is a **base** add-on (kind of organization core) providing custom entity datatypes, e.g.:

  • java.time.Duration
  • java.time.Period
  • java.time.MonthDay
  • java.time.YearMonth
  • java.time.ZoneOffset

Other custom add-on are using them implicitly by defining (JPA and DTO) entities. But since Jmix 2.0 the contextLoads() test fail:

org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.jmix.core.impl.MetadataLoader]: Constructor threw exception
    at app//org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:224)
    at app//org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:110)
    at app//org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:323)
    ... 164 more

    Caused by: java.lang.IllegalStateException: Can't find range class 'java.time.ZoneOffset' for property 'ls**mdl_***SystemInfoDTO.zoneOffset'
        Caused by:
            at io.jmix.core.impl.MetaModelLoader$RangeInitTask.execute(MetaModelLoader.java:1075)
            at io.jmix.core.impl.MetaModelLoader.loadModel(MetaModelLoader.java:145)
            at io.jmix.core.impl.MetadataLoader.<init>(MetadataLoader.java:61)
            at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
            at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
            at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
            at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
            at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:211)
            ... 166 more

I experienced a problem with a similar reading symptom some time ago: https://forum.jmix.io/t/using-custom-datatype-from-another-module-add-on/945/4. Neither me nor Jmix studio changed the module configuration while migrating from Jmix 1.5.3 to 2.0.1.

Trying to find some documentation about changed datatype handling, I noticed the modules API https://docs.jmix.io/jmix/modularity/extension.html#modules-api. I could not solve the issue but helped debugging the loaded modules and datatypes. The custom addons/modules are there, but the new datatypes are missing (22 datatypes defined by jmix core only):

Jmix-2.0.1_missing-custom-datatypes

I still need some help to find out why custom datatypes are not loaded.

Dear support,

are there any news on this topic? The issue stops me from migration any application.

Hello,

I’m working on your problem, I will revert back to you after I find a solution.

Regards,
Nikita

1 Like

Hello @shchienko

are there any news on this topic?

Dear support,

it’s been a while since the last response in August. Are there still no news on that topic?

I’m still wondering when or even if I can start using Jmix 2.

Hello,

Sorry, I lost track of the topic. Created a test project with custom datatype.

In the add-on I created a custom datatype from the documentation - Data Types :: Jmix Documentation.

The standard add-on configuration is enough to work:

@Configuration
@ComponentScan
@ConfigurationPropertiesScan
@JmixModule(dependsOn = {EclipselinkConfiguration.class, FlowuiConfiguration.class})
@PropertySource(name = "com.company.ja", value = "classpath:/com/company/ja/module.properties")
public class JaConfiguration {

Add-on with custom datatype:
jmix-datatype-example-addon.zip (13.3 KB)
jmix-datatype-example-addon-starter.zip (3.7 KB)

Test project with add-on:
jmix-datatype-example.zip (123.0 KB)

Regards,
Nikita

Hello @shchienko,

thank you for your response!

The add-ons which I am going to migrate are not depending on any UI. Both are very basic and are also used in REST-only applications (but UI applications as well):

  • the datatype providing add-on: base
    and
  • the datatype consuming/using add-on which defines DTO entities using one of these custom data types.

Both worked fine in Jmix 1.5.3. Is there an additional Jmix Module dependency which is required with Jmix 2.0.?

Can you provide a minimal demo project (Jmix 2.0) to quickly find a solution to your problem?

@shchienko I spent a couple of days creating a kind-of-public example and and could not reproduce the issue with the example.

Then I noticed that the newly created example contained the spring-boot 3 way of registering auto configurations:
src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
additionally to the springboot 2 way:
src/main/resouces/META-INF/spring.factories

I added the imports-file which solved the issue.

My first migration attempt was in August 2023. So I cannot say which Jmix plugin version I used for the first attempt.