HHH-8223 - Implement @NamedEntityGraph binding

This commit is contained in:
Steve Ebersole 2013-05-17 12:49:47 -05:00
parent 21ae220a4c
commit 14993a4637
12 changed files with 320 additions and 34 deletions

View File

@ -209,6 +209,9 @@ public final class AnnotationBinder {
public static void bindDefaults(Mappings mappings) {
Map defaults = mappings.getReflectionManager().getDefaults();
// id generators ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
List<SequenceGenerator> anns = ( List<SequenceGenerator> ) defaults.get( SequenceGenerator.class );
if ( anns != null ) {
@ -231,6 +234,9 @@ public final class AnnotationBinder {
}
}
}
// queries ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
List<NamedQuery> anns = ( List<NamedQuery> ) defaults.get( NamedQuery.class );
if ( anns != null ) {
@ -247,6 +253,9 @@ public final class AnnotationBinder {
}
}
}
// result-set-mappings ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
List<SqlResultSetMapping> anns = ( List<SqlResultSetMapping> ) defaults.get( SqlResultSetMapping.class );
if ( anns != null ) {
@ -256,6 +265,8 @@ public final class AnnotationBinder {
}
}
// stored procs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
final List<NamedStoredProcedureQuery> annotations =
(List<NamedStoredProcedureQuery>) defaults.get( NamedStoredProcedureQuery.class );
@ -265,7 +276,6 @@ public final class AnnotationBinder {
}
}
}
{
final List<NamedStoredProcedureQueries> annotations =
(List<NamedStoredProcedureQueries>) defaults.get( NamedStoredProcedureQueries.class );

View File

@ -81,6 +81,8 @@ import org.hibernate.annotations.common.reflection.java.JavaReflectionManager;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
import org.hibernate.cache.spi.GeneralDataRegion;
import org.hibernate.cfg.annotations.NamedEntityGraphDefinition;
import org.hibernate.cfg.annotations.NamedProcedureCallDefinition;
import org.hibernate.cfg.annotations.reflection.JPAMetadataProvider;
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
@ -217,6 +219,7 @@ public class Configuration implements Serializable {
protected Map<String, NamedSQLQueryDefinition> namedSqlQueries;
protected Map<String, NamedProcedureCallDefinition> namedProcedureCallMap;
protected Map<String, ResultSetMappingDefinition> sqlResultSetMappings;
protected Map<String, NamedEntityGraphDefinition> namedEntityGraphMap;
protected Map<String, TypeDef> typeDefs;
protected Map<String, FilterDefinition> filterDefinitions;
@ -299,6 +302,7 @@ public class Configuration implements Serializable {
namedQueries = new HashMap<String,NamedQueryDefinition>();
namedSqlQueries = new HashMap<String,NamedSQLQueryDefinition>();
sqlResultSetMappings = new HashMap<String, ResultSetMappingDefinition>();
namedEntityGraphMap = new HashMap<String, NamedEntityGraphDefinition>();
typeDefs = new HashMap<String,TypeDef>();
filterDefinitions = new HashMap<String, FilterDefinition>();
@ -2619,6 +2623,12 @@ public class Configuration implements Serializable {
}
}
public java.util.Collection<NamedEntityGraphDefinition> getNamedEntityGraphs() {
return namedEntityGraphMap == null
? Collections.<NamedEntityGraphDefinition>emptyList()
: namedEntityGraphMap.values();
}
// Mappings impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -2886,6 +2896,16 @@ public class Configuration implements Serializable {
}
}
@Override
public void addNamedEntityGraphDefintion(NamedEntityGraphDefinition definition)
throws DuplicateMappingException {
final String name = definition.getRegisteredName();
final NamedEntityGraphDefinition previous = namedEntityGraphMap.put( name, definition );
if ( previous != null ) {
throw new DuplicateMappingException( "NamedEntityGraph", name );
}
}
public void addDefaultSQLQuery(String name, NamedSQLQueryDefinition query) {
applySQLQuery( name, query );
defaultNamedNativeQueryNames.add( name );

View File

@ -37,6 +37,7 @@ import org.hibernate.MappingException;
import org.hibernate.annotations.AnyMetaDef;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.cfg.annotations.NamedEntityGraphDefinition;
import org.hibernate.cfg.annotations.NamedProcedureCallDefinition;
import org.hibernate.engine.ResultSetMappingDefinition;
import org.hibernate.engine.spi.FilterDefinition;
@ -348,6 +349,15 @@ public interface Mappings {
*/
public void addNamedProcedureCallDefinition(NamedProcedureCallDefinition definition) throws DuplicateMappingException;
/**
* Adds metadata for a named entity graph to this repository
*
* @param namedEntityGraphDefinition The procedure call information
*
* @throws DuplicateMappingException If an entity graph already exists with that name.
*/
public void addNamedEntityGraphDefintion(NamedEntityGraphDefinition namedEntityGraphDefinition);
/**
* Get the metadata for a named SQL result set mapping.
*

View File

@ -35,6 +35,8 @@ import javax.persistence.Access;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.NamedEntityGraph;
import javax.persistence.NamedEntityGraphs;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.SecondaryTable;
import javax.persistence.SecondaryTables;
@ -162,8 +164,28 @@ public class EntityBinder {
this.annotatedClass = annotatedClass;
bindEjb3Annotation( ejb3Ann );
bindHibernateAnnotation( hibAnn );
processNamedEntityGraphs();
}
private void processNamedEntityGraphs() {
processNamedEntityGraph( annotatedClass.getAnnotation( NamedEntityGraph.class ) );
final NamedEntityGraphs graphs = annotatedClass.getAnnotation( NamedEntityGraphs.class );
if ( graphs != null ) {
for ( NamedEntityGraph graph : graphs.value() ) {
processNamedEntityGraph( graph );
}
}
}
private void processNamedEntityGraph(NamedEntityGraph annotation) {
if ( annotation == null ) {
return;
}
mappings.addNamedEntityGraphDefintion( new NamedEntityGraphDefinition( annotation, name, persistentClass.getEntityName() ) );
}
@SuppressWarnings("SimplifiableConditionalExpression")
private void bindHibernateAnnotation(org.hibernate.annotations.Entity hibAnn) {
{

View File

@ -0,0 +1,59 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.cfg.annotations;
import javax.persistence.NamedEntityGraph;
/**
* Models the definition of a {@link NamedEntityGraph} annotation
*
* @author Steve Ebersole
*/
public class NamedEntityGraphDefinition {
private final NamedEntityGraph annotation;
private final String jpaEntityName;
private final String entityName;
public NamedEntityGraphDefinition(NamedEntityGraph annotation, String jpaEntityName, String entityName) {
this.annotation = annotation;
this.jpaEntityName = jpaEntityName;
this.entityName = entityName;
}
public String getRegisteredName() {
return jpaEntityName;
}
public String getJpaEntityName() {
return jpaEntityName;
}
public String getEntityName() {
return entityName;
}
public NamedEntityGraph getAnnotation() {
return annotation;
}
}

View File

@ -162,42 +162,42 @@ public abstract class AbstractGraphNode<T> implements GraphNodeImplementor {
}
@SuppressWarnings("unchecked")
public <X> Subgraph<X> addSubgraph(Attribute<T, X> attribute) {
public <X> SubgraphImpl<X> addSubgraph(Attribute<T, X> attribute) {
return addAttribute( attribute ).makeSubgraph();
}
@SuppressWarnings("unchecked")
public <X> Subgraph<? extends X> addSubgraph(Attribute<T, X> attribute, Class<? extends X> type) {
public <X> SubgraphImpl<? extends X> addSubgraph(Attribute<T, X> attribute, Class<? extends X> type) {
return addAttribute( attribute ).makeSubgraph( type );
}
@SuppressWarnings("unchecked")
public <X> Subgraph<X> addSubgraph(String attributeName) {
public <X> SubgraphImpl<X> addSubgraph(String attributeName) {
return addAttribute( attributeName ).makeSubgraph();
}
@SuppressWarnings("unchecked")
public <X> Subgraph<X> addSubgraph(String attributeName, Class<X> type) {
public <X> SubgraphImpl<X> addSubgraph(String attributeName, Class<X> type) {
return addAttribute( attributeName ).makeSubgraph( type );
}
@SuppressWarnings("unchecked")
public <X> Subgraph<X> addKeySubgraph(Attribute<T, X> attribute) {
public <X> SubgraphImpl<X> addKeySubgraph(Attribute<T, X> attribute) {
return addAttribute( attribute ).makeKeySubgraph();
}
@SuppressWarnings("unchecked")
public <X> Subgraph<? extends X> addKeySubgraph(Attribute<T, X> attribute, Class<? extends X> type) {
public <X> SubgraphImpl<? extends X> addKeySubgraph(Attribute<T, X> attribute, Class<? extends X> type) {
return addAttribute( attribute ).makeKeySubgraph( type );
}
@SuppressWarnings("unchecked")
public <X> Subgraph<X> addKeySubgraph(String attributeName) {
public <X> SubgraphImpl<X> addKeySubgraph(String attributeName) {
return addAttribute( attributeName ).makeKeySubgraph();
}
@SuppressWarnings("unchecked")
public <X> Subgraph<X> addKeySubgraph(String attributeName, Class<X> type) {
public <X> SubgraphImpl<X> addKeySubgraph(String attributeName, Class<X> type) {
return addAttribute( attributeName ).makeKeySubgraph( type );
}
}

View File

@ -108,16 +108,16 @@ public class AttributeNodeImpl<T> implements AttributeNode<T>, AttributeNodeImpl
}
@SuppressWarnings("unchecked")
public <T> Subgraph<T> makeSubgraph() {
return (Subgraph<T>) internalMakeSubgraph( null );
public <T> SubgraphImpl<T> makeSubgraph() {
return (SubgraphImpl<T>) internalMakeSubgraph( null );
}
@SuppressWarnings("unchecked")
public <X extends T> Subgraph<X> makeSubgraph(Class<X> type) {
return (Subgraph<X>) internalMakeSubgraph( type );
public <X extends T> SubgraphImpl<X> makeSubgraph(Class<X> type) {
return (SubgraphImpl<X>) internalMakeSubgraph( type );
}
private Subgraph internalMakeSubgraph(Class type) {
private SubgraphImpl internalMakeSubgraph(Class type) {
if ( attribute.getPersistentAttributeType() == Attribute.PersistentAttributeType.BASIC
|| attribute.getPersistentAttributeType() == Attribute.PersistentAttributeType.EMBEDDED ) {
throw new IllegalArgumentException(
@ -193,12 +193,17 @@ public class AttributeNodeImpl<T> implements AttributeNode<T>, AttributeNodeImpl
return type.isAssignableFrom( entityPersister.getMappedClass() );
}
public <T> Subgraph<T> makeKeySubgraph() {
return (SubgraphImpl<T>) makeKeySubgraph( null );
@SuppressWarnings("unchecked")
public <T> SubgraphImpl<T> makeKeySubgraph() {
return (SubgraphImpl<T>) internalMakeKeySubgraph( null );
}
@SuppressWarnings("unchecked")
public <X extends T> Subgraph<X> makeKeySubgraph(Class<X> type) {
public <X extends T> SubgraphImpl<X> makeKeySubgraph(Class<X> type) {
return (SubgraphImpl<X>) internalMakeKeySubgraph( type );
}
public SubgraphImpl internalMakeKeySubgraph(Class type) {
if ( ! attribute.isCollection() ) {
throw new IllegalArgumentException(
String.format( "Non-collection attribute [%s] cannot be target of key subgraph", getAttributeName() )

View File

@ -83,42 +83,42 @@ public class EntityGraphImpl<T> extends AbstractGraphNode<T> implements EntityGr
}
@Override
public <X> Subgraph<X> addSubgraph(Attribute<T, X> attribute) {
public <X> SubgraphImpl<X> addSubgraph(Attribute<T, X> attribute) {
return super.addSubgraph( attribute );
}
@Override
public <X> Subgraph<? extends X> addSubgraph(Attribute<T, X> attribute, Class<? extends X> type) {
public <X> SubgraphImpl<? extends X> addSubgraph(Attribute<T, X> attribute, Class<? extends X> type) {
return super.addSubgraph( attribute, type );
}
@Override
public <X> Subgraph<X> addSubgraph(String attributeName) {
public <X> SubgraphImpl<X> addSubgraph(String attributeName) {
return super.addSubgraph( attributeName );
}
@Override
public <X> Subgraph<X> addSubgraph(String attributeName, Class<X> type) {
public <X> SubgraphImpl<X> addSubgraph(String attributeName, Class<X> type) {
return super.addSubgraph( attributeName, type );
}
@Override
public <X> Subgraph<X> addKeySubgraph(Attribute<T, X> attribute) {
public <X> SubgraphImpl<X> addKeySubgraph(Attribute<T, X> attribute) {
return super.addKeySubgraph( attribute );
}
@Override
public <X> Subgraph<? extends X> addKeySubgraph(Attribute<T, X> attribute, Class<? extends X> type) {
public <X> SubgraphImpl<? extends X> addKeySubgraph(Attribute<T, X> attribute, Class<? extends X> type) {
return super.addKeySubgraph( attribute, type );
}
@Override
public <X> Subgraph<X> addKeySubgraph(String attributeName) {
public <X> SubgraphImpl<X> addKeySubgraph(String attributeName) {
return super.addKeySubgraph( attributeName );
}
@Override
public <X> Subgraph<X> addKeySubgraph(String attributeName, Class<X> type) {
public <X> SubgraphImpl<X> addKeySubgraph(String attributeName, Class<X> type) {
return super.addKeySubgraph( attributeName, type );
}

View File

@ -68,42 +68,42 @@ public class SubgraphImpl<T> extends AbstractGraphNode<T> implements Subgraph<T>
}
@Override
public <X> Subgraph<X> addSubgraph(Attribute<T, X> attribute) {
public <X> SubgraphImpl<X> addSubgraph(Attribute<T, X> attribute) {
return super.addSubgraph( attribute );
}
@Override
public <X> Subgraph<? extends X> addSubgraph(Attribute<T, X> attribute, Class<? extends X> type) {
public <X> SubgraphImpl<? extends X> addSubgraph(Attribute<T, X> attribute, Class<? extends X> type) {
return super.addSubgraph( attribute, type );
}
@Override
public <X> Subgraph<X> addSubgraph(String attributeName) {
public <X> SubgraphImpl<X> addSubgraph(String attributeName) {
return super.addSubgraph( attributeName );
}
@Override
public <X> Subgraph<X> addSubgraph(String attributeName, Class<X> type) {
public <X> SubgraphImpl<X> addSubgraph(String attributeName, Class<X> type) {
return super.addSubgraph( attributeName, type );
}
@Override
public <X> Subgraph<X> addKeySubgraph(Attribute<T, X> attribute) {
public <X> SubgraphImpl<X> addKeySubgraph(Attribute<T, X> attribute) {
return super.addKeySubgraph( attribute );
}
@Override
public <X> Subgraph<? extends X> addKeySubgraph(Attribute<T, X> attribute, Class<? extends X> type) {
public <X> SubgraphImpl<? extends X> addKeySubgraph(Attribute<T, X> attribute, Class<? extends X> type) {
return super.addKeySubgraph( attribute, type );
}
@Override
public <X> Subgraph<X> addKeySubgraph(String attributeName) {
public <X> SubgraphImpl<X> addKeySubgraph(String attributeName) {
return super.addKeySubgraph( attributeName );
}
@Override
public <X> Subgraph<X> addKeySubgraph(String attributeName, Class<X> type) {
public <X> SubgraphImpl<X> addKeySubgraph(String attributeName, Class<X> type) {
return super.addKeySubgraph( attributeName, type );
}

View File

@ -27,12 +27,16 @@ import javax.persistence.Cache;
import javax.persistence.EntityGraph;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.NamedAttributeNode;
import javax.persistence.NamedEntityGraph;
import javax.persistence.NamedSubgraph;
import javax.persistence.PersistenceContextType;
import javax.persistence.PersistenceException;
import javax.persistence.PersistenceUnitUtil;
import javax.persistence.Query;
import javax.persistence.SynchronizationType;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.EntityType;
import javax.persistence.metamodel.Metamodel;
import javax.persistence.spi.LoadState;
@ -42,6 +46,7 @@ import java.io.InvalidObjectException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@ -55,6 +60,7 @@ import org.hibernate.Hibernate;
import org.hibernate.SessionFactory;
import org.hibernate.cache.spi.RegionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.annotations.NamedEntityGraphDefinition;
import org.hibernate.ejb.HibernateEntityManagerFactory;
import org.hibernate.engine.spi.NamedQueryDefinition;
import org.hibernate.engine.spi.NamedQueryDefinitionBuilder;
@ -64,12 +70,15 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.UUIDGenerator;
import org.hibernate.internal.SessionFactoryImpl;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.jpa.AvailableSettings;
import org.hibernate.jpa.HibernateQuery;
import org.hibernate.jpa.boot.internal.SettingsImpl;
import org.hibernate.jpa.criteria.CriteriaBuilderImpl;
import org.hibernate.jpa.graph.internal.AbstractGraphNode;
import org.hibernate.jpa.graph.internal.EntityGraphImpl;
import org.hibernate.jpa.graph.internal.SubgraphImpl;
import org.hibernate.jpa.internal.metamodel.EntityTypeImpl;
import org.hibernate.jpa.internal.metamodel.MetamodelImpl;
import org.hibernate.jpa.internal.util.PersistenceUtilHelper;
@ -161,7 +170,10 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
entityManagerFactoryName = (String) UUID_GENERATOR.generate(null, null);
}
this.entityManagerFactoryName = entityManagerFactoryName;
EntityManagerFactoryRegistry.INSTANCE.addEntityManagerFactory(entityManagerFactoryName, this);
applyNamedEntityGraphs( cfg.getNamedEntityGraphs() );
EntityManagerFactoryRegistry.INSTANCE.addEntityManagerFactory( entityManagerFactoryName, this );
}
private enum JpaMetaModelPopulationSetting {
@ -220,6 +232,68 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
}
}
@SuppressWarnings("unchecked")
private void applyNamedEntityGraphs(Collection<NamedEntityGraphDefinition> namedEntityGraphs) {
for ( NamedEntityGraphDefinition definition : namedEntityGraphs ) {
final EntityType entityType = metamodel.getEntityTypeByName( definition.getJpaEntityName() );
final EntityGraphImpl entityGraph = new EntityGraphImpl(
definition.getRegisteredName(),
entityType,
this
);
final NamedEntityGraph namedEntityGraph = definition.getAnnotation();
if ( namedEntityGraph.includeAllAttributes() ) {
for ( Object attributeObject : entityType.getAttributes() ) {
entityGraph.addAttributeNodes( (Attribute) attributeObject );
}
}
if ( namedEntityGraph.attributeNodes() != null ) {
applyNamedAttributeNodes( namedEntityGraph.attributeNodes(), namedEntityGraph, entityGraph );
}
entityGraphs.put( definition.getRegisteredName(), entityGraph );
}
}
private void applyNamedAttributeNodes(
NamedAttributeNode[] namedAttributeNodes,
NamedEntityGraph namedEntityGraph,
AbstractGraphNode graphNode) {
for ( NamedAttributeNode namedAttributeNode : namedAttributeNodes ) {
if ( StringHelper.isNotEmpty( namedAttributeNode.subgraph() ) ) {
final SubgraphImpl subgraph = graphNode.addSubgraph( namedAttributeNode.value() );
applyNamedSubgraphs(
namedEntityGraph,
namedAttributeNode.subgraph(),
subgraph
);
}
if ( StringHelper.isNotEmpty( namedAttributeNode.keySubgraph() ) ) {
final SubgraphImpl subgraph = graphNode.addKeySubgraph( namedAttributeNode.value() );
applyNamedSubgraphs(
namedEntityGraph,
namedAttributeNode.keySubgraph(),
subgraph
);
}
}
}
private void applyNamedSubgraphs(NamedEntityGraph namedEntityGraph, String subgraphName, SubgraphImpl subgraph) {
for ( NamedSubgraph namedSubgraph : namedEntityGraph.subgraphs() ) {
if ( subgraphName.equals( namedSubgraph.name() ) ) {
applyNamedAttributeNodes(
namedSubgraph.attributeNodes(),
namedEntityGraph,
subgraph
);
}
}
}
public EntityManager createEntityManager() {
return createEntityManager( Collections.EMPTY_MAP );
}

View File

@ -0,0 +1,48 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.test.graphs.named.basic;
import javax.persistence.EntityGraph;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.junit.Test;
import static junit.framework.Assert.assertNotNull;
/**
* @author Steve Ebersole
*/
public class BasicNamedEntityGraphTest extends BaseEntityManagerFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { Person.class };
}
@Test
public void testIt() {
EntityGraph graph = getOrCreateEntityManager().getEntityGraph( "Person" );
assertNotNull( graph );
}
}

View File

@ -0,0 +1,38 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.test.graphs.named.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedEntityGraph;
/**
* @author Steve Ebersole
*/
@Entity(name = "Person")
@NamedEntityGraph()
public class Person {
@Id
private Long id;
}