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

@Inheritance / DiscriminatorColumn stops working in EBean 15 (upgrade from 14) #3475

Open
tbee opened this issue Sep 10, 2024 · 2 comments
Open
Assignees

Comments

@tbee
Copy link
Contributor

tbee commented Sep 10, 2024

Given these classes:

@Entity
@Table(name = "product")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.INTEGER)
public abstract class Product extends BaseWithSave<Product> implements RegistrationProduct, Transferable<ProductTO>, Auditable {
}
@Entity
@DiscriminatorValue("0")
public class OtherProduct extends Product {
}

The annotations are in the jakarta.persistence package.

Expected behavior

This should work:

  DB.find(Product.class).findList();

Actual behavior

java.lang.UnsupportedOperationException: cannot create entity bean for abstract entity Product
at deployment.ioserver.ear//io.ebeaninternal.server.deploy.BeanDescriptor.createEntityBean(BeanDescriptor.java:1405)
at deployment.ioserver.ear//io.ebeaninternal.server.deploy.BeanDescriptor.createEntityBean2(BeanDescriptor.java:1445)
at deployment.ioserver.ear//io.ebeaninternal.server.query.SqlTreeLoadBean$Load.initBeanType(SqlTreeLoadBean.java:129)
at deployment.ioserver.ear//io.ebeaninternal.server.query.SqlTreeLoadBean$Load.initialise(SqlTreeLoadBean.java:308)
at deployment.ioserver.ear//io.ebeaninternal.server.query.SqlTreeLoadBean$Load.perform(SqlTreeLoadBean.java:320)
at deployment.ioserver.ear//io.ebeaninternal.server.query.SqlTreeLoadBean.load(SqlTreeLoadBean.java:343)
at deployment.ioserver.ear//io.ebeaninternal.server.query.SqlTreeLoadRoot.load(SqlTreeLoadRoot.java:26)
at deployment.ioserver.ear//io.ebeaninternal.server.query.CQuery.readNextBean(CQuery.java:389)
at deployment.ioserver.ear//io.ebeaninternal.server.query.CQuery.hasNext(CQuery.java:466)
at deployment.ioserver.ear//io.ebeaninternal.server.query.CQuery.readCollection(CQuery.java:495)
at deployment.ioserver.ear//io.ebeaninternal.server.query.CQueryEngine.findMany(CQueryEngine.java:343)
at deployment.ioserver.ear//io.ebeaninternal.server.query.DefaultOrmQueryEngine.findMany(DefaultOrmQueryEngine.java:126)
at deployment.ioserver.ear//io.ebeaninternal.server.core.OrmQueryRequest.findList(OrmQueryRequest.java:380)
at deployment.ioserver.ear//io.ebeaninternal.server.core.DefaultServer.findList(DefaultServer.java:1329)
at deployment.ioserver.ear//io.ebeaninternal.server.core.DefaultServer.findList(DefaultServer.java:1311)
at deployment.ioserver.ear//io.ebeaninternal.server.querydefn.DefaultOrmQuery.findList(DefaultOrmQuery.java:1489)
at deployment.integration-test.war//com.nedap.healthcare.administration.finance.TestProductFinder.simple(TestProductFinder.java:38)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)```

Somehow it tries to instantiate the abstract class or something. Continuing the investigation

@tbee tbee changed the title DiscriminatorColumn stops working in EBean 15 DiscriminatorColumn stops working in EBean 15 (upgrade from 14) Sep 10, 2024
@rbygrave
Copy link
Member

upgrade from 14

Ah no we literally can't upgrade to 15 with an application that uses @Inheritance. We have to keep those applications on 14, which is to say that 14 and 15 are the same but with various features removed from 15 and that includes support for @Inheritance which might sound drastic but there is some background reading referenced below.

Refer to:
https://github.com/ebean-orm/ebean/releases/tag/15.0.0-RC

And refer to the discussions leading up to it at:
#3112

So ponder those discussions etc but no we need to stay on 14 for apps using @inheritance [and this is why we need to keep releasing both 14 and 15 etc]. Also apologies because I need to improve 15 to better error when it detects inheritance mapping.

@rbygrave rbygrave self-assigned this Sep 10, 2024
@tbee
Copy link
Contributor Author

tbee commented Sep 10, 2024

Oh my. I can understand you do not want to support all the more complex inheritance types, but single table is used a lot to do polymorphism: in this case have a generic product with 15 or so subtypes. It can just be some different behaviour, code only, but it is the natural (OOP) place for that code to live... And the ORM should return the correct class. Is it really so complex to instantiate and populate the correct class based on the discriminator?

@rbygrave rbygrave changed the title DiscriminatorColumn stops working in EBean 15 (upgrade from 14) @Inheritance / DiscriminatorColumn stops working in EBean 15 (upgrade from 14) Oct 8, 2024
@rbygrave rbygrave pinned this issue Oct 18, 2024
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