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

Allow projects to choose their ID generator #33

Open
manosbatsis opened this issue May 5, 2019 · 6 comments
Open

Allow projects to choose their ID generator #33

manosbatsis opened this issue May 5, 2019 · 6 comments

Comments

@manosbatsis
Copy link

manosbatsis commented May 5, 2019

AbstractUser pretty much bars applications from using their own ID generator, as it extends LemonEntity > AbstractPersistable, with the latter defining the ID member and JPA annotations. It would be much preferable to provide an interface VS AbstractUser or otherwise not include the id member definition within it or it's superclasses. In short, users should be able to:

// OR:  implements LemonUser<Integer>
public class User extends AbstractUser<Integer> {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
}
@naturalprogrammer
Copy link
Owner

👍 Good point. But in production apps, mostly some migration tool like Flyway would be used anyway. So, I feel like this issue isn't a high priority.

@manosbatsis
Copy link
Author

@naturalprogrammer can't really see how your comment relates to the issue, probably meant to post elsewhere?

@naturalprogrammer
Copy link
Owner

What I meant was, when you use Flyway like libraries (recommended approach) instead of depending on hibernate to generate the DDL, the JPA annotations of the id field are ignored anyways. Don't agree?

@manosbatsis
Copy link
Author

Not really. The real problem is the hardcoded Integer id type. What if you want to use a UUID or other non-integer type? Or need to implement another user interface? Long story short this is a composition VS inheritance issue. At worst this should be using generics.

Even if using evolution tools to override mappings wasn't a hack, JPA annotations are interpreted by frameworks like spring to e.g. to transparently save or update.

It's been a while though so this is not an issue anymore for us.

@naturalprogrammer
Copy link
Owner

Thanks for elaborating. But public class User extends AbstractUser<Integer> is your code (refer to getting started guide), which means you could replace the Integer with anything.

But I do agree that this could be better patternized, but I had kept quick start and simplicity in mind, while meeting all requirements (like the generic ID above) when designing the API.

@naturalprogrammer
Copy link
Owner

BTW, if it helps: it's possible to override the generation type by supplying a META-INF/orm.xml in resources, looking as below:

<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings
        xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm"
        version="2.2">

    <mapped-superclass class="org.springframework.data.jpa.domain.AbstractPersistable">
        <attributes>
            <id name="id">
                <generated-value strategy="IDENTITY" />
            </id>
        </attributes>
    </mapped-superclass>

</entity-mappings>

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

No branches or pull requests

2 participants