play-ebean
play-ebean copied to clipboard
custom IdGenerator fail
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?
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.
Where did you place your CustomServerStartupConfig class? It should be in the same package with your models.
On Sep 9, 2017 11:45 PM, "Koen De Groote" [email protected] wrote:
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/0a5ce1bee8e6317f4ef7c93087b6b0 f63e911a59/src/main/java/io/ebeaninternal/server/deploy/ parse/AnnotationFields.java#L506-L512
Which then goes to this:
https://github.com/ebean-orm/ebean/blob/0a5ce1bee8e6317f4ef7c93087b6b0 f63e911a59/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.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/playframework/play-ebean/issues/128#issuecomment-328307872, or mute the thread https://github.com/notifications/unsubscribe-auth/AGAfbKDjRzmrFDAjgcOu5D_MYZmwv5hLks5sgxT8gaJpZM4PSFeX .
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.
Sorry, markdown foramt wrong. It is indeed in app/models
I found bootup work
https://github.com/ebean-orm/ebean/blob/ebean-10.3.1/src/main/java/io/ebeaninternal/server/core/DefaultContainer.java#L204
before my customserverconfig
https://github.com/ebean-orm/ebean/blob/ebean-10.3.1/src/main/java/io/ebeaninternal/server/core/DefaultContainer.java#L215