omnifaces / omnipersistence

Utilities for JPA, JDBC and DataSources
Other
31 stars 12 forks source link

Added functionality for non-autoincremented id fields. #10

Closed skuntsel closed 6 years ago

skuntsel commented 6 years ago

Added support for id fields that don't need autoincrement functionality that were otherwise impossible to be modelled. To achieve this goal an additional base class was introduced that doesn't have an id field preset (in this update BaseEntity is the base class for all entities that must control its id generation manually and BaseAutoIdEntity is the base class for the entities with autogenerated ids).

Right now there is a possiblility to map the following two entities (e.g. country lookup table with char code primary key and standard auto-id entity):

@Entity
public class StringIdEntity extends BaseEntity<String> {

    @Id
    @Column(length = 2, nullable = false, unique = true)
    private String id;

    @Override
    public String getId() {
        return id;
    }

    @Override
    public void setId(String id) {
        this.id = id;
    }

    //...

}

and

@Entity
public class IntIdEntity extends BaseAutoIdEntity<Long> {

    //...

}

BaseEntityService can now be used with both entities:

@Stateless
public class StringIdEntityService extends BaseEntityService<String, StringIdEntity> {

}

and

@Stateless
public class IntIdEntityService extends BaseEntityService<Long, IntIdEntity> {

}

It also leaves an opportunity to have a base class with id field that must support anything different from GenerationType.IDENTITY, e.g. GenerationType.SEQUENCE, as it could otherwise only be modified on a per-mapped superclass basis via xml and thus have impact on all implementing classes.

BalusC commented 6 years ago

Next time please create PR on develop branch.

skuntsel commented 6 years ago

Ok, that somehow got missed out of sight. Please don’t forget to merge BaseEntityService class into develop branch alongside refreshed BaseEntity classes as well for the latter to work correctly.

BalusC commented 6 years ago

Yep, looking into it already, but got distracted.

Cheers, B

On Tue, Mar 27, 2018, 20:45 skuntsel notifications@github.com wrote:

Ok, that somehow got missed out of sight. Please don’t forget to merge BaseEntityService class into develop branch alongside refreshed BaseEntity classes as well for the latter to work correctly.

— You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub https://github.com/omnifaces/omnipersistence/pull/10#issuecomment-376633110, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKlPOCxQSJjColpK4bKKF1G_xN9OExAks5tiojegaJpZM4S9HKd .