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

HHH-19072 The hibernate.session_factory_name configuration property no longer works in Hibernate 7.0.0 #9679

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static org.hibernate.cfg.PersistenceSettings.PERSISTENCE_UNIT_NAME;
import static org.hibernate.cfg.PersistenceSettings.SESSION_FACTORY_JNDI_NAME;
import static org.hibernate.cfg.PersistenceSettings.SESSION_FACTORY_NAME;
import static org.hibernate.cfg.ValidationSettings.JAKARTA_VALIDATION_FACTORY;
import static org.hibernate.cfg.ValidationSettings.JPA_VALIDATION_FACTORY;
import static org.hibernate.engine.config.spi.StandardConverters.STRING;
Expand Down Expand Up @@ -95,6 +96,10 @@ static String determineJndiName(
return explicitJndiName;
}
else {
final String expliciSessionFactoryname = configService.getSetting( SESSION_FACTORY_NAME, STRING );
if ( isNotEmpty( expliciSessionFactoryname ) ) {
return expliciSessionFactoryname;
}
final String unitName = configService.getSetting( PERSISTENCE_UNIT_NAME, STRING );
// do not use name for JNDI if explicitly asked not to or if name comes from JPA persistence-unit name
final boolean nameIsNotJndiName =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.internal;

import org.assertj.core.api.Assertions;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
import static org.hibernate.orm.test.internal.SessionFactoryNameSettingTest.SESSION_FACTORY_NAME;

@Jpa(
integrationSettings = @Setting(name = AvailableSettings.SESSION_FACTORY_NAME, value = SESSION_FACTORY_NAME)
)
@JiraKey("HHH-19072")
public class SessionFactoryNameSettingTest {
public static final String SESSION_FACTORY_NAME = "TEST_SESSION_FACTORY";

@Test
public void testSessionFactoryNameSettingInfluencingSessionFactoryName(EntityManagerFactoryScope scope) {
assertThat( scope.getEntityManagerFactory().unwrap( SessionFactory.class ).getName() )
.isEqualTo( SESSION_FACTORY_NAME );
}

@Test
public void testSessionFactoryNameSettingInfluencingSessionFactoryJndiName(EntityManagerFactoryScope scope) {
Assertions.assertThat( scope.getEntityManagerFactory().unwrap( SessionFactory.class ).getJndiName() )
.isEqualTo( SESSION_FACTORY_NAME );
}
}