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

custom IdGenerator fail #128

Open
techzhou opened this issue Sep 9, 2017 · 4 comments
Open

custom IdGenerator fail #128

techzhou opened this issue Sep 9, 2017 · 4 comments

Comments

@techzhou
Copy link

techzhou commented Sep 9, 2017

package utils;

import io.ebean.config.IdGenerator;

public class EbeanIdGenerator implements IdGenerator {

    private static final UniqueId uid = new UniqueId();

    @Override
    public Object nextValue() {
        return uid.getStringId();
    }

    @Override
    public String getName() {
        return "ccID";
    }
}
package models;

import io.ebean.config.ServerConfig;
import io.ebean.event.ServerConfigStartup;
import utils.EbeanIdGenerator;

public class CustomServerConfigStartup implements ServerConfigStartup {
    @Override
    public void onStart(ServerConfig serverConfig) {
        serverConfig.add(new EbeanIdGenerator());
    }
}
@Entity
public class Catalog extends Model {
    @Id
    @GeneratedValue(generator = "ccID")
    public String id;

I got fail message

Caused by: java.lang.IllegalStateException: No custom IdGenerator registered with name ccID
at io.ebeaninternal.server.deploy.parse.AnnotationFields.readGenValue(AnnotationFields.java:511)
at io.ebeaninternal.server.deploy.parse.AnnotationFields.readField(AnnotationFields.java:176)
at io.ebeaninternal.server.deploy.parse.AnnotationFields.parse(AnnotationFields.java:84)
at io.ebeaninternal.server.deploy.parse.ReadAnnotations.readInitial(ReadAnnotations.java:57)
at io.ebeaninternal.server.deploy.BeanDescriptorManager.createDeployBeanInfo(BeanDescriptorManager.java:1180)
at io.ebeaninternal.server.deploy.BeanDescriptorManager.readEntityDeploymentInitial(BeanDescriptorManager.java:677)
at io.ebeaninternal.server.deploy.BeanDescriptorManager.deploy(BeanDescriptorManager.java:321)
at io.ebeaninternal.server.core.InternalConfiguration.(InternalConfiguration.java:141)
at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:130)
at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:44)

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "4.0.2")

Was there anything wrong with what I did?

@KoenDG
Copy link
Contributor

KoenDG commented Sep 9, 2017

This is the code in ebean that throws the exception(for version 10.3.1, which is the version sbt-play-ebean 4.0.2 uses):

https://github.com/ebean-orm/ebean/blob/0a5ce1bee8e6317f4ef7c93087b6b0f63e911a59/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationFields.java#L506-L512

Which then goes to this:

https://github.com/ebean-orm/ebean/blob/0a5ce1bee8e6317f4ef7c93087b6b0f63e911a59/src/main/java/io/ebeaninternal/server/deploy/generatedproperty/GeneratedPropertyFactory.java#L118-L120

So it looks like the override isn't actually being registered. I had a look here: https://www.playframework.com/documentation/2.6.x/JavaEbean

And it looks like you followed the example from that page, which begs the question: is the example correct/complete? Maybe it was written for an older version? Not sure.

I'm not part of the dev team btw, just had some time to kill.

Have you tried binding it in your Module? Like so: https://playframework.com/documentation/2.6.x/JavaDependencyInjection#eager-bindings

Not sure if it's necessary but might be that Play isn't aware of the override unless you force it to do an eager singleton on it during startup.

@oexza
Copy link

oexza commented Sep 10, 2017 via email

@KoenDG
Copy link
Contributor

KoenDG commented Sep 10, 2017

Where did you place your CustomServerStartupConfig class? It should be in
the same package with your models.

@oexza That's not mentioned in the Play documentation. Also, I'm not the original poster. Just mentioning it since GitHub is making it look like you replied to me directly.

@techzhou
Copy link
Author

techzhou commented Sep 11, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants