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

Make it easier to use the auto-configured EntityManagerFactoryBuilder with Hibernate-specific properties #15318

Closed
petenattress opened this issue Nov 28, 2018 · 5 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@petenattress
Copy link

This relates to #3654 - I was asked to open a new issue by @wilkinsona.

When I followed the guidance in the Spring Boot documentation on how to define two entity managers, the mappings for my original entity manager stopped working, with exceptions such as this:

Caused by: org.hibernate.MappingException: Unable to find column with logical name: some_id in some_table
	at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:858) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
...

As #3654 describes, this was due to the EntityManagerFactoryBuilder not containing the Spring naming_strategy properties which are populated by the auto-configuration when Boot creates the entity manager itself. This took me a while to get to the bottom of because the documentation does not point this out, in fact it kind of implies that the EntityManagerFactoryBuilder can be used to construct an entity manager in the same way the auto-configuration does.

For my use case, it would be useful if the EntityManagerFactoryBuilder contained the same set of properties created by the auto-configuration, especially to preserve the "clever" behaviour of the ddl-auto option being set differently for integration tests against an embedded database. As is, I am required to replicate this behaviour in my configuration class - I have done this for now by wiring in the properties that I could (this isn't identical to the auto-configuration, but it's close enough for my current needs):

@Bean
public LocalContainerEntityManagerFactoryBean myEntityManagerFactory(EntityManagerFactoryBuilder builder,
                                                                     DataSource dataSource,
                                                                     JpaProperties jpaProperties,
                                                                     HibernateProperties hibernateProperties) {
  HibernateSettings hibernateSettings = new HibernateSettings();

  return builder
      .dataSource(dataSource)
      .properties(hibernateProperties.determineHibernateProperties(jpaProperties.getProperties(), hibernateSettings))
      .packages(SomePackage.class)
      .persistenceUnit("someUnit")
      .build();
}

I understand that other use cases may not find the auto-population of properties useful, and that making such a change is probably not backwards compatible. If the change is not possible, I think the documentation should be updated to clarify the behaviour and ideally demonstrate how to work around it like in my example above. Perhaps as a compromise, there could be a nicer way of wiring in the result of the call to hibernateProperties.determineHibernateProperties, which I think is all I need.

Many thanks.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 28, 2018
@philwebb philwebb added the for: team-attention An issue we'd like other members of the team to review label Nov 28, 2018
@wilkinsona wilkinsona changed the title EntityManagerFactoryBuilder - set properties as per auto-configuration or update documentation Make it easier to use the auto-configured EntityManagerFactoryBuilder with Hibernate-specific properties Nov 30, 2018
@wilkinsona wilkinsona added type: enhancement A general enhancement for: team-meeting and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Nov 30, 2018
@wilkinsona wilkinsona added this to the 2.2.x milestone Nov 30, 2018
@wilkinsona
Copy link
Member

Thank you, @petenattress. We're going to improve the documentation in 2.1.x (#15361) and take a look at making it easier to use the auto-configured Hibernate properties in 2.2.

@petenattress
Copy link
Author

Many thanks @wilkinsona, that sounds good.

@philwebb
Copy link
Member

Issue #15738 will allow us to revisit and redesign EntityManagerFactoryBuilder.

@wilkinsona wilkinsona modified the milestones: 2.2.x, 2.x May 17, 2019
@wilkinsona wilkinsona added the status: blocked An issue that's blocked on an external project change label May 17, 2019
@wilkinsona
Copy link
Member

wilkinsona commented May 17, 2019

To avoid changing this now and again later on, this seems to be blocked until we figure out #15738.

@wilkinsona wilkinsona removed the status: blocked An issue that's blocked on an external project change label May 4, 2022
@philwebb philwebb modified the milestones: 2.x, 3.x Aug 19, 2022
@snicoll
Copy link
Member

snicoll commented Aug 5, 2024

If I understood this ask correctly, it's about moving

Map<String, Object> vendorProperties = getVendorProperties();
customizeVendorProperties(vendorProperties);

a few lines up so that it's applied to the auto-configured EntityManagerFactoryBuilder.

@snicoll snicoll closed this as completed in 4030090 Aug 5, 2024
@snicoll snicoll modified the milestones: 3.x, 3.4.0-M2 Aug 5, 2024
@snicoll snicoll self-assigned this Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants