{"action":"created","issue":{"url":"https://api.github.com/repos/spring-projects/spring-boot/issues/4960","labels_url":"https://api.github.com/repos/spring-projects/spring-boot/issues/4960/labels{/name}","comments_url":"https://api.github.com/repos/spring-projects/spring-boot/issues/4960/comments","events_url":"https://api.github.com/repos/spring-projects/spring-boot/issues/4960/events","html_url":"https://github.com/spring-projects/spring-boot/issues/4960","id":127119175,"number":4960,"title":"Hazelcast cannot use EntityManager","user":{"login":"messo","id":316335,"avatar_url":"https://avatars.githubusercontent.com/u/316335?v=3","gravatar_id":"","url":"https://api.github.com/users/messo","html_url":"https://github.com/messo","followers_url":"https://api.github.com/users/messo/followers","following_url":"https://api.github.com/users/messo/following{/other_user}","gists_url":"https://api.github.com/users/messo/gists{/gist_id}","starred_url":"https://api.github.com/users/messo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/messo/subscriptions","organizations_url":"https://api.github.com/users/messo/orgs","repos_url":"https://api.github.com/users/messo/repos","events_url":"https://api.github.com/users/messo/events{/privacy}","received_events_url":"https://api.github.com/users/messo/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/spring-projects/spring-boot/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":{"login":"snicoll","id":490484,"avatar_url":"https://avatars.githubusercontent.com/u/490484?v=3","gravatar_id":"","url":"https://api.github.com/users/snicoll","html_url":"https://github.com/snicoll","followers_url":"https://api.github.com/users/snicoll/followers","following_url":"https://api.github.com/users/snicoll/following{/other_user}","gists_url":"https://api.github.com/users/snicoll/gists{/gist_id}","starred_url":"https://api.github.com/users/snicoll/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snicoll/subscriptions","organizations_url":"https://api.github.com/users/snicoll/orgs","repos_url":"https://api.github.com/users/snicoll/repos","events_url":"https://api.github.com/users/snicoll/events{/privacy}","received_events_url":"https://api.github.com/users/snicoll/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/spring-projects/spring-boot/milestones/50","html_url":"https://github.com/spring-projects/spring-boot/milestones/1.3.2","labels_url":"https://api.github.com/repos/spring-projects/spring-boot/milestones/50/labels","id":1462925,"number":50,"title":"1.3.2","description":"","creator":{"login":"philwebb","id":519772,"avatar_url":"https://avatars.githubusercontent.com/u/519772?v=3","gravatar_id":"","url":"https://api.github.com/users/philwebb","html_url":"https://github.com/philwebb","followers_url":"https://api.github.com/users/philwebb/followers","following_url":"https://api.github.com/users/philwebb/following{/other_user}","gists_url":"https://api.github.com/users/philwebb/gists{/gist_id}","starred_url":"https://api.github.com/users/philwebb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philwebb/subscriptions","organizations_url":"https://api.github.com/users/philwebb/orgs","repos_url":"https://api.github.com/users/philwebb/repos","events_url":"https://api.github.com/users/philwebb/events{/privacy}","received_events_url":"https://api.github.com/users/philwebb/received_events","type":"User","site_admin":false},"open_issues":16,"closed_issues":30,"state":"open","created_at":"2015-12-16T10:13:54Z","updated_at":"2016-01-18T16:07:05Z","due_on":"2016-01-21T00:00:00Z","closed_at":null},"comments":5,"created_at":"2016-01-17T19:58:16Z","updated_at":"2016-01-18T17:19:47Z","closed_at":null,"body":"Dear @snicoll and others,\r\n\r\nI see a potential problem with **HazelcastJpaDependencyAutoConfiguration**. As the comment says: *Additional configuration to ensure that* **EntityManagerFactory** *beans depend-on the* **hazelcastInstance** *bean*.\r\n\r\nThe issue with this that it is not possible to use MapStore implementations backed by JPA.\r\nThe reason is that the EntityManager cannot be injected into a MapStore implementation, since it is not yet created (first HazelcastInstance must be created). But MapStore is needed to create the Config bean, which is needed for the HazelcastInstance...\r\n\r\nSo my HazelcastConfig looks like this:\r\n```java\r\n@Configuration\r\npublic class HazelcastConfig {\r\n\r\n    @Bean\r\n    public Config config(TradeMapStore tradeMapStore) {\r\n        return new Config()\r\n                .addMapConfig(\r\n                        new MapConfig(\"trades\")\r\n                                .setMapStoreConfig(\r\n                                        new MapStoreConfig()\r\n                                                .setImplementation(tradeMapStore)\r\n                                                .setWriteDelaySeconds(0) // write-through\r\n                                )\r\n                );\r\n    }\r\n```\r\n\r\nAnd the MapStore impl:\r\n```java\r\n@Repository\r\npublic class TradeMapStore implements MapStore<Long, Trade> {\r\n\r\n    @PersistenceContext\r\n    private EntityManager em;\r\n\r\n    [...]\r\n}\r\n```\r\n\r\nWhat do you suggest to circumvent this issue?\r\n\r\nThanks!"},"comment":{"url":"https://api.github.com/repos/spring-projects/spring-boot/issues/comments/172596311","html_url":"https://github.com/spring-projects/spring-boot/issues/4960#issuecomment-172596311","issue_url":"https://api.github.com/repos/spring-projects/spring-boot/issues/4960","id":172596311,"user":{"login":"snicoll","id":490484,"avatar_url":"https://avatars.githubusercontent.com/u/490484?v=3","gravatar_id":"","url":"https://api.github.com/users/snicoll","html_url":"https://github.com/snicoll","followers_url":"https://api.github.com/users/snicoll/followers","following_url":"https://api.github.com/users/snicoll/following{/other_user}","gists_url":"https://api.github.com/users/snicoll/gists{/gist_id}","starred_url":"https://api.github.com/users/snicoll/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snicoll/subscriptions","organizations_url":"https://api.github.com/users/snicoll/orgs","repos_url":"https://api.github.com/users/snicoll/repos","events_url":"https://api.github.com/users/snicoll/events{/privacy}","received_events_url":"https://api.github.com/users/snicoll/received_events","type":"User","site_admin":false},"created_at":"2016-01-18T17:19:47Z","updated_at":"2016-01-18T17:19:47Z","body":"That helps, thank you. So we have such link on the caching support as well so we need to take that into account. \r\n\r\n`CacheAutoConfiguration#CacheManagerJpaDependencyConfiguration` adds a reference so that the `CacheManager` is fully loaded before the `EntityManager` (Hibernate 2nd level cache use case). \r\n\r\nWe have the same link in the Hazelcast support so if we want to fully address this  concern we need to fix that in two places.\r\n\r\nCurrent proposal:\r\n\r\n* introduce a `spring.hazelcast.mode` with a `HazelcastMode` enum that can be `HIBERNATE_CACHE` or `PRIMARY_STORE`. This would flip the dependency order\r\n* introduce a `spring.cache.l2.enabled` that would be enabled by default. Disabling this means that we should disable the link that is added if hibernate is available.\r\n\r\nThe second property can also be used tot let Spring Boot auto-configure the Hibernate 2nd level cache support: it is a feature that we don't have right now and that I do not intend to implement in the 1.3 line. So maybe we'll have to wait for that and provide another way to disable that link for now."}}