Extending StandardEntity with some functionality

I’m building an artifact to communicate with Windows Domain Controller over LDAP, I’d like to get CRUD AD functionality into my Entity, so I can call i.e. myUserLikeEntity.createAdAccount(). I’m struggeling getting the StandardEntity extended so I can use it as base for MyUserLikeEntity.


@MappedSuperclass
@MetaClass(name = "adintegration_AdEnabledEntity")
@UnavailableInSecurityConstraints
public class AdEnabledEntity extends StandardEntity {
    private static final long serialVersionUID = 5642226839555253331L;

    public boolean updateAdAccount(){
        // do stuff
        return true;
    }

    public boolean createAdAccount(){
        // do stuff
        return true;
    }

    public Map<Object, Object> getDifferences() {
        return null;
    }

    public String getDistinguishedName(){
        return null;
    }

    // ...
}

so at the end I want to have …

@Table(name = "ADINTEGRATION_MY_USER_LIKE_ENTITY")
@Entity(name = "adintegration_MyUserLikeEntity")
@NamePattern("%s|name")
public class MyUserLikeEntity extends AdEnabledEntity {
    private static final long serialVersionUID = 7825474395058037176L;

    @Column(name = "NAME")
    private String name;

// ...

Although I solved the issue with an Interface and default methods, I still want to know, where I would register the AdEnabledEntity class, so I can use it instead of StandardEntity.

Hi,
There is no setting to make your own class automatically used as a parent class for new entities.
However you can change entity’s parent class in the Entity Designer (with “Parent:” field).

Thanks for the reply, but that doesn’t really answer my question. The AdEnabledEntity doesnt have to come up as default when creating new Entities. I am getting errors and the system doesn’t start when I used the AdEnabledEntity in the Parent field.
My assumption is (and I’m still far from being a Java Expert) that you need to register the class somewhere… Maybe in the persistance.xml or similar, I have no idea. Or maybe functional methods are just not allowed, but they must as we can create computed fields in the entities…
Anyway, if my question isn’t clear enough, I’m happy to leave it unanswered as I found a different (more elagant) way with the interface.

Well, yes, you need to register all entities including @MappedSuperclass-es in the persistence.xml file. Studio does that if you create the entity with Studio action.

1 Like