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

Panache support for not initialized proxies #9602

Open
suchwerk opened this issue May 26, 2020 · 13 comments
Open

Panache support for not initialized proxies #9602

suchwerk opened this issue May 26, 2020 · 13 comments
Labels
area/panache kind/enhancement New feature or request

Comments

@suchwerk
Copy link
Contributor

Description
The use-case is to add not-initilized proxies to a set inside a panache entity. Right now i have to inject the entity manager to access getReference. It would be nice if PanacheEntityBase itself would implement getReference.

So

    @Inject
    EntityManager entityManager;
    ids.forEach(id->list.add(entityManager.getReference(Item.class, id)) );

to be replaced by something like:

    ids.forEach(id->list.add(Item.getReference(id)));
@suchwerk suchwerk added the kind/enhancement New feature or request label May 26, 2020
@Sanne
Copy link
Member

Sanne commented May 26, 2020

I agree, this would be very useful. Thanks for opening!

@FroMage : I suppose this is doable?

@FroMage
Copy link
Member

FroMage commented May 26, 2020

You can use Panache.getEntityManager() as well. But yeah, probably we could add this feature, but is it really common enough, do you think @Sanne ?

@suchwerk
Copy link
Contributor Author

suchwerk commented May 26, 2020

I guess only passing ids from a webapi is not that unusual and:

 ids.forEach(id->list.add(Item.getReference(id)));

looks leaner vs.

 ids.forEach(id->list.add(Panache.getEntityManager().getReference(Item.class, id)));

@FroMage
Copy link
Member

FroMage commented May 26, 2020

Sure, I don't question that. But we don't want to add every Hibernate feature in a Panache layer because that would make the API huge and scary. So we always try to resist additions to the most common use-cases that people need. Hence my question to @Sanne but perhaps @emmanuelbernard has an idea too.

@Sanne
Copy link
Member

Sanne commented May 26, 2020

You can't easily update collections without this .. so yes I'd say it's commonly useful. As many other things :)

@Sanne
Copy link
Member

Sanne commented May 26, 2020

Although TBH Panache.getEntityManager().getReference(.. doesn't look too bad - your call @FroMage

@FroMage
Copy link
Member

FroMage commented May 26, 2020

If I give you Entity getReference(Object id), I'll have to give you List<Entity> getReferences(Object... ids) too because ids.forEach(id->list.add(Item.getReference(id))); is just yuck compared to Item.getReferences(ids).

@emmanuelbernard
Copy link
Member

Hum, getReference is a relatively useful optimisation but using it to get loads of entities to add to a List is less common.
Personally I'm getting scared of Panache's own weight and would resist adding these two features. But I might in my ivory tower.

@loicmathieu
Copy link
Contributor

I tend to agree with @emmanuelbernard, then people will want findReference(query, params) with all the variations because, you usually list via a query not via known ids ...

@suchwerk what do you do with those references you get ? Maybe we're missing a different functionality here ?

@suchwerk
Copy link
Contributor Author

@loicmathieu I just want to add them to a jointable.

@ryckowski
Copy link

I'm using myEntity.setRelated(getReference(Related.clas, id)) quite often to set the related entity and there's no reason fetch it. From sql point of view just want to set foreign key id which I know
Is there a better practise?

@gavinking
Copy link

gavinking commented Jan 13, 2021

Hum, getReference is a relatively useful optimisation but using it to get loads of entities to add to a List is less common.

I agree but it looks like the mentioned usage is a bit misleading?

All that's described is adding Item.getReference(id), which is definitely needed IMO. (Nothing specific to lists in that.)

@gaetanBloch
Copy link

gaetanBloch commented Sep 21, 2023

Just discussed this issue with @yrodiere and will work on a PR on Panache in a near future!

@yrodiere yrodiere changed the title Panache support for not initilized proxies Panache support for not initialized proxies Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/panache kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

8 participants