Problems while trying to extend User entity

I am trying to extend the User entity to add more properties as shown below:

package com.calidus.pdcs.entity;

import io.jmix.core.entity.annotation.CaseConversion;
import io.jmix.core.metamodel.annotation.JmixEntity;

import javax.persistence.Column;
import javax.persistence.Entity;

@JmixEntity
@Entity
public class ExtendedUser extends User {
@CaseConversion
@Column(name = “EXU_ACRONYM”, length = 4)
private String exuAcronym;

public String getExuAcronym() {
    return exuAcronym;
}

public void setExuAcronym(String exuAcronym) {
    this.exuAcronym = exuAcronym;
}

}

Then I have a helper class that tries to query the database for the currently logged user, as below:

package com.calidus.pdcs.entity;

import io.jmix.core.DataManager;
import io.jmix.core.security.CurrentAuthentication;
import org.springframework.security.core.userdetails.UserDetails;

public interface ExtendedUserHelper {
public static User getCurrentUser(CurrentAuthentication currentAuthentication, DataManager dataManager){
// Returns the currently logged user instance
UserDetails userDetails = currentAuthentication.getUser();
return dataManager.load(User.class)
.query(“select exu from ExtendedUser exu where exu.username = :exun”)
.parameter(“exun”, userDetails.getUsername())
.one();
}
}

The problem is that the currently logged user (admin) is not being found and an exception is being raised by the query.

What is wrong with this implementation?

image

Hello!

Could you clarify do you specify the inheritance strategy for User entity?

I guess, that is used default SINGLE_TABLE, so you have one DB table for two JPQL entities. User and ExtendedUser have different DTYPE value. It means if you create User (e.g. using default editor or DataManager) it won’t be found from ExtendedUser JPQL query.

The admin user is created via 010-init-user.xml changelog file. If you want to make it ExtendedUser, you should add DTYPE value (the name of ExtendedUser entity).

Thanks Roman!

For the moment, I just changed the dtype for the admin user to “ExtendedUser” but I doubt it is the best solution. I don´t know yet the consequences when I try to use the security features of Jmix.
Later I will go deeper into this issue.

Regards.