How to use custom IdGenerator (IdType.GENERATOR)?

361 views
Skip to first unread message

Heinrich Spreiter

unread,
May 7, 2012, 4:35:06 PM5/7/12
to Ebean ORM
Hello

I've created a custom IdGenerator but I have yet to find a way to use
it for my entities. Is there an annotation or configuration that I can
use?

I use ebean 2.7.3.

Thanks!
Heinrich Spreiter

Rob Bygrave

unread,
May 8, 2012, 12:55:24 AM5/8/12
to eb...@googlegroups.com
No there is not.

Out of curiosity ... what does your IdGenerator do?

Heinrich Spreiter

unread,
May 8, 2012, 1:09:50 AM5/8/12
to Ebean ORM
Hi Rob

It is like the UUID generator but uses JUG.
I saw that there is a DatabasePlattform object that
creates such generators. Is there a way to override that?



On 8 Mai, 06:55, Rob Bygrave <robin.bygr...@gmail.com> wrote:
> No there is not.
>
> Out of curiosity ... what does your IdGenerator do?
>

Rob Bygrave

unread,
May 8, 2012, 7:39:39 AM5/8/12
to eb...@googlegroups.com
The database platform is more for DB Identity and DB Sequence's.

So not sure if you are using this ...
https://github.com/cowtowncoder/java-uuid-generator/blob/3.0/src/test/java/com/fasterxml/uuid/SimpleGenerationTest.java

If the UUID generator generates java.util.UUID and you use the java.util.UUID type in your domain objects then I'd say the best approach is to get Ebean to allow pluggable implementations of the UUID generation.  Ebean already automatically assigns its UUIDGenerator to domain objects whose Id field is of type java.util.UUID.

@Id UUID id;

... so if this was your case then you just need to swap out the default implementation with your own (enhance Ebean to allow a pluggable UUIDGenerator implementation).


If instead you use a String type for your id rather than java.util.UUID ... then Ebean should add a @UUID annotation (there is an existing enhancement request to do this) so it would look like:

@UUID @Id String id;


If you want to use some type other than String or java.util.UUID then more thinking is required probably.


Cheers, Rob.

Heinrich Spreiter

unread,
May 8, 2012, 2:07:12 PM5/8/12
to Ebean ORM
I use ebean with play 2.0.1 so I don' want to switch the ebean version
or used a patched one. Instead I'll use javassist to replace the
UuidIdGenerator.nextId() method with my own implementation on
application startup.

If I find time I will also implement it for ebean so there is no need
for javassist.

Thanks for your help!

Cheers, Heinrich

On 8 Mai, 13:39, Rob Bygrave <robin.bygr...@gmail.com> wrote:
> The database platform is more for DB Identity and DB Sequence's.
>
> So not sure if you are using this ...https://github.com/cowtowncoder/java-uuid-generator/blob/3.0/src/test...
>
> If the UUID generator generates java.util.UUID and you use the
> java.util.UUID type in your domain objects then I'd say the best approach
> is to get Ebean to allow pluggable implementations of the UUID generation.
> Ebean already automatically assigns its UUIDGenerator to domain objects
> whose Id field is of type java.util.UUID.
>
> @Id UUID id;
>
> ... so if this was your case then you just need to swap out the default
> implementation with your own (enhance Ebean to allow a pluggable
> UUIDGenerator implementation).
>
> If instead you use a String type for your id rather than java.util.UUID ...
> then Ebean should add a @UUID annotation (there is an existing enhancement
> request to do this) so it would look like:
>
> @UUID @Id String id;
>
> If you want to use some type other than String or java.util.UUID then more
> thinking is required probably.
>
> Cheers, Rob.
>
Reply all
Reply to author
Forward
0 new messages