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

Enhance LocalSessionFactoryBuilder to offer ability to addHibernateProperties and addMappingResources [SPR-8815] #13457

Closed
spring-projects-issues opened this issue Nov 3, 2011 · 2 comments
Assignees
Labels
in: core status: declined type: enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 3, 2011

Chris Phillipson opened SPR-8815 and commented

Would like to enhance current functionality of LocalSessionFactoryBuilder w/ support for methods found in old AnnotationSessionFactoryBean, specifically support for adding hibernate.properties and referencing *.hbm.xml files on classpath.

This is not too much effort in my opinion.

Below is code sample impl from a subclass I implemented earlier, that could just as well be promoted into the aforementioned builder. Of course, this is dependent on fix for https://jira.springsource.org/browse/SPR-8776 to be released in order to fully realize its potential.

private static final Method addProperties =
ClassUtils.getMethodIfAvailable(Configuration.class, "addProperties", Properties.class);

private static final Method addResource =
ClassUtils.getMethodIfAvailable(Configuration.class, "addResource", String.class);

/**
 * Set Hibernate mapping resources to be found in the class path,
 * like "example.hbm.xml" or "mypackage/example.hbm.xml".
 * Analogous to mapping entries in a Hibernate XML config file.
 * <p>Can be used to add to mappings from a Hibernate XML config file,
 * or to specify all mappings locally.
 * @see org.hibernate.cfg.Configuration#addResource
 */
public LocalSessionFactoryBuilder addMappingResources(String... mappingResources) {
    for (String mappingResource :mappingResources) {
        ReflectionUtils.invokeMethod(addResource, this, mappingResource);
    }
    return this;
}

/**
 * Set Hibernate properties, such as "hibernate.dialect".
 * <p>Can be used to override values in a Hibernate XML config file,
 * or to specify all necessary properties locally.
 * <p>Note: Do not specify a transaction provider here when using
 * Spring-driven transactions. It is also advisable to omit connection
 * provider settings and use a Spring-set DataSource instead.
 */
public LocalSessionFactoryBuilder addHibernateProperties(Properties properties) {
    ReflectionUtils.invokeMethod(addProperties, this, properties);
    return this;
}

Affects: 3.1 RC1

Attachments:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 3, 2011

Chris Phillipson commented

The sample code in the description got mangled. Attached is source from a derivative of LocalSessionFactoryBuilder that should illustrate what I'm after.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Oct 27, 2014

Juergen Hoeller commented

This doesn't seem to be worth it at this point since both of those methods are just simple adapters for standard Hibernate methods inherited from Configuration. I'd rather recommend using the standard methods, even if this means calling one method per mapping resource.

On an additional note, there are quite a few variants of specifying resources with LocalSessionFactoryBean, all of which could be provided on LocalSessionFactoryBuilder... They are just arguably less commonly used there, so the current state doesn't seem so bad.

Juergen

@spring-projects-issues spring-projects-issues added status: declined type: enhancement in: core labels Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core status: declined type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants