Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality for non-autoincremented id fields. #10

Merged
merged 1 commit into from
Mar 27, 2018

Conversation

skuntsel
Copy link
Contributor

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 BalusC merged commit f390715 into omnifaces:master Mar 27, 2018
@BalusC
Copy link
Member

BalusC commented Mar 27, 2018

Next time please create PR on develop branch.

@skuntsel
Copy link
Contributor Author

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
Copy link
Member

BalusC commented Mar 27, 2018 via email

@skuntsel skuntsel deleted the master branch March 28, 2018 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants