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

QueryBean IllegalAccessError is thrown with @Embeddable and @EmbeddedId in different packages #3586

Open
casmir opened this issue Mar 5, 2025 · 1 comment

Comments

@casmir
Copy link

casmir commented Mar 5, 2025

We are trying to update to a later version of Ebean (coming from 12.x) , but are encountering some errors while doing so.
One of them is related to Querybeans throwing an IllegalAccessError with @embeddable class in another package.

Expected behavior

We expect the following line to work without throwing an exception.

new QContentWithEmbeddedId().select(QContentWithEmbeddedId.alias().embeddableId).findList()

QueryBeans not to throw the IllegalAccessError when the @embeddable class is not in the same package.
We're reusing an @embeddable class in multiple Entities, therefore have moved it to another 'common' package structure.

This issue/bug was introduced after #3455 . (14.5.0 works, 14.6.0 onwards fails)

Actual behavior

An IllegalAccessError is thrown:

java.lang.IllegalAccessError: class org.example.content.model.query.QContentWithEmbeddedId tried to access protected method 'void org.example.common.embedded.query.QEmbeddableId$Assoc.<init>(java.lang.String, java.lang.Object)' (org.example.content.model.query.QContentWithEmbeddedId and org.example.common.embedded.query.QEmbeddableId$Assoc are in unnamed module of loader 'app')
	at org.example.content.model.query.QContentWithEmbeddedId.<init>(QContentWithEmbeddedId.java:3)
	at org.example.content.model.query.QContentWithEmbeddedId.<clinit>(QContentWithEmbeddedId.java:16)

Steps to reproduce

Created sample project : https://github.com/casmir/ebean-querybean-protected-assoc

Create an embeddable class in one package and use that with an Entity in another package.

package org.example.common.embedded;

@Embeddable
public class EmbeddableId {

    @Column(length = 19)
    private Long id;

    @Column(length = 50)
    private String other;

 ....
}
package org.example.content.model;

import org.example.common.embedded.EmbeddableId;

@Entity
@Table(name="product_history")
public class ContentWithEmbeddedId extends Model {

    @EmbeddedId
    private EmbeddableId embeddableId;
    
.....

}

From what I can tell it is related to the change made in file :
querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleQueryBeanWriter.java

writeAssocBeanConstructor("protected Assoc");

Could you tell me if this is indeed a bug, or has this been done for a particular reason.

Thanks,

Cas

@rbygrave
Copy link
Member

rbygrave commented Mar 9, 2025

This is a bug, I'll prepare a PR to fix it.

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