Issue Type: Bug Bug
Assignee: Unassigned
Created: 21/Jun/12 8:22 AM
Description:

Currently named queries (NamedQueryDefinition) are kept in HashMap registries on the SessionFactory. Would make more sense to have kept them in a immutable map for performance reasons.

However, the JPA 2.1 spec adds a feature to add (and override) named queries at runtime. So this will not universally be an option. What we would like to do here is two-fold:

First is to add a new contract that would allow programatic definition and regsitration of named queries as part of the SessionFactory bootstrap process. Initially thinking:

interface NamedQueryProvider {
    public processNamedQueries(NamedQueryDefinitionBuilderFactory factory);
}

Jokes about a "builder factory aside"

interface NamedQueryDefinitionBuilderFactory {
    public NamedQueryDefinitionBuilder makeNamedQueryDefinitionBuilder();
    public NamedSQLQueryDefinitionBuilder makeNamedSQLQueryDefinitionBuilder();
}

NamedQueryDefinitionBuilder and NamedSQLQueryDefinitionBuilder are typical builders. NamedSQLQueryDefinitionBuilder extends
NamedQueryDefinitionBuilder, in much the same way that NamedSQLQueryDefinition extends NamedQueryDefinition.

The second point is to change how these definitions are stored on SessionFactory. As mentioned above, they currently are stored using a HashMap. Ideally it would have made more sense to use a immutable map since the contents used to not change after SessionFactory creation. However, that mentioned JPA 2.1 feature changes that. The proposal then is to define a new setting to indicate whether the use plans on using the ability to register named query definitions using EntityManagerFactory/SessionFactory. If not, we can go ahead and make the stores here immutable maps; if so we should probably switch to using ConcurrentHashMap anyway.

It is important to note that the simultaneous use of the immutable maps and NamedQueryProvider is fully supported.

Fix Versions: jpa21
Project: Hibernate ORM
Priority: Major Major
Reporter: Steve Ebersole
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira