# Chicken and egg problem with @SqlFragmentAlias

**URL:** <https://discourse.hibernate.org/t/chicken-and-egg-problem-with-sqlfragmentalias/1355>\
**Category:** Hibernate ORM\
**Created:** [September 6, 2018, 10:10pm UTC](https://discourse.hibernate.org/t/chicken-and-egg-problem-with-sqlfragmentalias/1355 "2018-09-06T22:10:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bas](https://avatars.discourse-cdn.com/v4/letter/b/a587f6/32.png) [@bas](https://discourse.hibernate.org/u/bas)\
**Post date:** [September 6, 2018, 10:10pm UTC](https://discourse.hibernate.org/t/chicken-and-egg-problem-with-sqlfragmentalias/1355/1 "2018-09-06T22:10:49Z")

</div>

I have a entity A with an @Filter definition with an SqlFragmentAlias using entity B.

```auto
    @Filter(
            name = "myFilter",
            condition =
                    "{alias}.AHC_ID = {allowed}.AHC_ID and {allowed}.PERSON_ID=:"
                            + AHCScopedFilters.P_PERSONID,
            deduceAliasInjectionPoints = false,
            aliases = {
                @SqlFragmentAlias(alias = "allowed", entity=B.class)
            })

```

When hibernate creates the factory it blows up with an entity not found exception “B”.  
We are using JPA running in jBoss EAP 7 that uses hibernate 5.0

Both classes are defined in the persistence.xml file and what I see is that the metadata.getEntityBindings contains all of our classes. The problem arises in the SessionFactoryImpl constructor that loops through the metaData.entityBindings and then adds them to its own entityPersisters map.  
It first processes entity A and when it handles the filter it then throws that exception because it is looking into this persisters map but entity B has not been processes yet and thus is not in that map yet.

Is this a bug or is there some property I can set that will do some 2-phased approach when loading the entities ?

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [September 7, 2018, 5:09am UTC](https://discourse.hibernate.org/t/chicken-and-egg-problem-with-sqlfragmentalias/1355/2 "2018-09-07T05:09:47Z")

</div>

Sounds like a bug. Try to replicate it [like this](http://in.relation.to/2018/06/04/best-way-write-hibernate-orm-issue-test-case/) or with our [test case template](http://in.relation.to/2016/01/14/hibernate-jpa-test-case-template/) and open a Jira issue afterward.

---

<div class="post-metadata">

**Author:** ![bas](https://avatars.discourse-cdn.com/v4/letter/b/a587f6/32.png) [@bas](https://discourse.hibernate.org/u/bas)\
**Post date:** [September 7, 2018, 6:37pm UTC](https://discourse.hibernate.org/t/chicken-and-egg-problem-with-sqlfragmentalias/1355/3 "2018-09-07T18:37:48Z")

</div>

Thanks Vlad, I was able to re-create the problem in a test case and created [https://hibernate.atlassian.net/browse/HHH-12967](https://hibernate.atlassian.net/browse/HHH-12967)

Bas

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [September 8, 2018, 4:28am UTC](https://discourse.hibernate.org/t/chicken-and-egg-problem-with-sqlfragmentalias/1355/4 "2018-09-08T04:28:58Z")

</div>

Thanks for the Jira issue and test case.

---

<div class="post-metadata">

**Author:** ![bas](https://avatars.discourse-cdn.com/v4/letter/b/a587f6/32.png) [@bas](https://discourse.hibernate.org/u/bas)\
**Post date:** [September 18, 2018, 9:43pm UTC](https://discourse.hibernate.org/t/chicken-and-egg-problem-with-sqlfragmentalias/1355/5 "2018-09-18T21:43:43Z")

</div>

What is the normal timeframe for someone to read the issue?

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [September 19, 2018, 4:02am UTC](https://discourse.hibernate.org/t/chicken-and-egg-problem-with-sqlfragmentalias/1355/6 "2018-09-19T04:02:46Z")

</div>

There’s no timeframe. The team is focused on 6.0 development and only high priority issues get more attention.

If you want to see it fixed sooner, send us a Pull Request with the fix and we’ll review it. Pull Requests have a higher priority too.

---

<div class="post-metadata">

**Author:** ![bas](https://avatars.discourse-cdn.com/v4/letter/b/a587f6/32.png) [@bas](https://discourse.hibernate.org/u/bas)\
**Post date:** [September 19, 2018, 11:53pm UTC](https://discourse.hibernate.org/t/chicken-and-egg-problem-with-sqlfragmentalias/1355/7 "2018-09-19T23:53:46Z")

</div>

Good to know, I was waiting on some kind of acknowledgement thinking someone monitored that.  
I will need to set that up on my private laptop but will try to find some time.

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [September 20, 2018, 4:12am UTC](https://discourse.hibernate.org/t/chicken-and-egg-problem-with-sqlfragmentalias/1355/8 "2018-09-20T04:12:22Z")

</div>

Looking forward to reviewing your Pull Request.
