Replies: 2 comments 1 reply
|
I don't hate the idea, assuming it's restricted to declared |
|
OK, thank you. Here some ideas how it might look like: For the non-metamodel generation folks: For one ID: public <T> T generateId(Class<?> entityClass, String field, Class<T> returnValueClass) throws UnsupportedGeneratorException;For multiple IDs: public <T> List<T> generateIds(Class<?> entityClass, String field, Class<T> returnValueClass, int amountOfIDs) throws UnsupportedGeneratorException;The usage would be: T myId = generateId(MyEntity.class, "id", Long.class);e.g. For projects, which use the metamodel generation: First a new interface: public interface GeneratorSingularAttribute<X, T> extends SingularAttribute<X, T> {}Now the metamodel generator would use this interface instead of the SingularAttribute interface for fields, which are suitable, The new methods would be: for one ID: public <X, T> T generateId(GeneratorSingularAttribute<X, T> generatorAttribute);For multiple IDs: public <X, T> List<T> generateIds(GeneratorSingularAttribute<X, T> generatorAttribute, int amountOfIDs);The usage would be: T myId = generateId(MyEntity_.id);eg. |
Uh oh!
There was an error while loading. Please reload this page.
It seems, that there is ATM no vendor neutral API to achieve this. This could be very handy if you want to do some raw SQL inserts or use the upcoming EntityAgent.upsert() method. I have also an idea for an API for this. Is there any interest here?
All reactions