HHH-5233 Fixed implementation for multiple fetch profiles overrides. Cleaned up pom.
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19634 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
087f2b567a
commit
41b2416be4
|
@ -22,7 +22,9 @@
|
||||||
~ 51 Franklin Street, Fifth Floor
|
~ 51 Franklin Street, Fifth Floor
|
||||||
~ Boston, MA 02110-1301 USA
|
~ Boston, MA 02110-1301 USA
|
||||||
-->
|
-->
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -44,7 +46,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate</groupId>
|
||||||
<artifactId>hibernate-core</artifactId>
|
<artifactId>hibernate-core</artifactId>
|
||||||
<version>${version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate</groupId>
|
||||||
|
@ -55,9 +57,9 @@
|
||||||
<artifactId>hibernate-jpa-2.0-api</artifactId>
|
<artifactId>hibernate-jpa-2.0-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${groupId}</groupId>
|
<groupId>${project.groupId}</groupId>
|
||||||
<artifactId>hibernate-testing</artifactId>
|
<artifactId>hibernate-testing</artifactId>
|
||||||
<version>${version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -84,13 +86,6 @@
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<testResources>
|
<testResources>
|
||||||
<testResource>
|
|
||||||
<filtering>false</filtering>
|
|
||||||
<directory>src/test/java</directory>
|
|
||||||
<includes>
|
|
||||||
<include>**/*.xml</include>
|
|
||||||
</includes>
|
|
||||||
</testResource>
|
|
||||||
<testResource>
|
<testResource>
|
||||||
<filtering>true</filtering>
|
<filtering>true</filtering>
|
||||||
<directory>src/test/resources</directory>
|
<directory>src/test/resources</directory>
|
||||||
|
@ -116,7 +111,7 @@
|
||||||
<configuration>
|
<configuration>
|
||||||
<bytecodeInjections>
|
<bytecodeInjections>
|
||||||
<bytecodeInjection>
|
<bytecodeInjection>
|
||||||
<expression>${pom.version}</expression>
|
<expression>${project.version}</expression>
|
||||||
<targetMembers>
|
<targetMembers>
|
||||||
<methodBodyReturn>
|
<methodBodyReturn>
|
||||||
<className>org.hibernate.cfg.annotations.Version</className>
|
<className>org.hibernate.cfg.annotations.Version</className>
|
||||||
|
|
|
@ -163,6 +163,7 @@ public class AnnotationConfiguration extends Configuration {
|
||||||
private boolean isValidatorNotPresentLogged;
|
private boolean isValidatorNotPresentLogged;
|
||||||
private Map<XClass, Map<String, PropertyData>> propertiesAnnotatedWithMapsId;
|
private Map<XClass, Map<String, PropertyData>> propertiesAnnotatedWithMapsId;
|
||||||
private Map<XClass, Map<String, PropertyData>> propertiesAnnotatedWithIdAndToOne;
|
private Map<XClass, Map<String, PropertyData>> propertiesAnnotatedWithIdAndToOne;
|
||||||
|
private Collection<FetchProfile> annotationConfiguredProfiles;
|
||||||
|
|
||||||
public AnnotationConfiguration() {
|
public AnnotationConfiguration() {
|
||||||
super();
|
super();
|
||||||
|
@ -268,7 +269,7 @@ public class AnnotationConfiguration extends Configuration {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExtendedMappings createExtendedMappings() {
|
public ExtendedMappings createExtendedMappings() {
|
||||||
return new ExtendedMappingsImpl();
|
return new ExtendedMappingsImpl( annotationConfiguredProfiles );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -311,6 +312,7 @@ public class AnnotationConfiguration extends Configuration {
|
||||||
reflectionManager = new JavaReflectionManager();
|
reflectionManager = new JavaReflectionManager();
|
||||||
( ( MetadataProviderInjector ) reflectionManager ).setMetadataProvider( new JPAMetadataProvider() );
|
( ( MetadataProviderInjector ) reflectionManager ).setMetadataProvider( new JPAMetadataProvider() );
|
||||||
configurationArtefactPrecedence = Collections.emptyList();
|
configurationArtefactPrecedence = Collections.emptyList();
|
||||||
|
annotationConfiguredProfiles = new HashSet<FetchProfile>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1255,8 +1257,8 @@ public class AnnotationConfiguration extends Configuration {
|
||||||
private Boolean useNewGeneratorMappings;
|
private Boolean useNewGeneratorMappings;
|
||||||
private Collection<FetchProfile> annotationConfiguredProfile;
|
private Collection<FetchProfile> annotationConfiguredProfile;
|
||||||
|
|
||||||
public ExtendedMappingsImpl() {
|
public ExtendedMappingsImpl(Collection<FetchProfile> fetchProfiles) {
|
||||||
annotationConfiguredProfile = new ArrayList<FetchProfile>();
|
annotationConfiguredProfile = fetchProfiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDefaultGenerator(IdGenerator generator) {
|
public void addDefaultGenerator(IdGenerator generator) {
|
||||||
|
@ -1528,11 +1530,15 @@ public class AnnotationConfiguration extends Configuration {
|
||||||
return anyMetaDefs.get( name );
|
return anyMetaDefs.get( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAnnotationConfiguredFetchProfile(FetchProfile fetchProfile) {
|
public FetchProfile findOrCreateFetchProfile(String name) {
|
||||||
annotationConfiguredProfile.add( fetchProfile );
|
FetchProfile profile = super.findOrCreateFetchProfile( name );
|
||||||
|
if ( profile.getFetches().isEmpty() ) {
|
||||||
|
annotationConfiguredProfile.add( profile );
|
||||||
|
}
|
||||||
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsAnnotationConfiguredFetchProfile(FetchProfile fetchProfile) {
|
public boolean isAnnotationConfiguredFetchProfile(FetchProfile fetchProfile) {
|
||||||
for ( FetchProfile profile : annotationConfiguredProfile ) {
|
for ( FetchProfile profile : annotationConfiguredProfile ) {
|
||||||
// we need reference equality there!!
|
// we need reference equality there!!
|
||||||
if ( profile == fetchProfile ) {
|
if ( profile == fetchProfile ) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// $Id:$
|
// $Id$
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
|
@ -207,14 +207,8 @@ public interface ExtendedMappings extends Mappings {
|
||||||
void addToOneAndIdProperty(XClass entity, PropertyData property);
|
void addToOneAndIdProperty(XClass entity, PropertyData property);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the specified profile to the list of fetch profiles configured via annotations.
|
* @param fetchProfile The fetch profile to test.
|
||||||
*
|
* @return {@code true} if the provided fetch profile has been configured via annotations, {@code false} otherwise.
|
||||||
* @param fetchProfile the fetch profile
|
|
||||||
*/
|
*/
|
||||||
void addAnnotationConfiguredFetchProfile(FetchProfile fetchProfile);
|
boolean isAnnotationConfiguredFetchProfile(FetchProfile fetchProfile);
|
||||||
|
|
||||||
/**
|
|
||||||
* @return {@true} if the provided fetch profile has been configured via xml, {@false otherwise}.
|
|
||||||
*/
|
|
||||||
boolean containsAnnotationConfiguredFetchProfile(FetchProfile fetchProfile);
|
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
// $Id:$
|
// $Id$
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
|
@ -47,7 +47,7 @@ public class VerifyFetchProfileReferenceSecondPass implements SecondPass {
|
||||||
|
|
||||||
public void doSecondPass(Map persistentClasses) throws MappingException {
|
public void doSecondPass(Map persistentClasses) throws MappingException {
|
||||||
org.hibernate.mapping.FetchProfile profile = mappings.findOrCreateFetchProfile( fetchProfileName );
|
org.hibernate.mapping.FetchProfile profile = mappings.findOrCreateFetchProfile( fetchProfileName );
|
||||||
if ( skipProfile( profile ) ) {
|
if ( !mappings.isAnnotationConfiguredFetchProfile( profile ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,15 +59,6 @@ public class VerifyFetchProfileReferenceSecondPass implements SecondPass {
|
||||||
fetch.entity().getName(), fetch.association(), fetch.mode().toString().toLowerCase()
|
fetch.entity().getName(), fetch.association(), fetch.mode().toString().toLowerCase()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean skipProfile(org.hibernate.mapping.FetchProfile profile) {
|
|
||||||
if ( mappings.containsAnnotationConfiguredFetchProfile( profile ) ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if there are fetches they must come from xml. If there are xml profiles the annotations get ignored
|
|
||||||
return !profile.getFetches().isEmpty();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,28 @@
|
||||||
|
// $Id: FetchProfileTest.java 19528 2010-05-17 14:28:55Z epbernard $
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010, Red Hat Middleware LLC 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 Middleware LLC.
|
||||||
|
*
|
||||||
|
* 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.test.annotations.fetchprofile;
|
package org.hibernate.test.annotations.fetchprofile;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -5,17 +30,16 @@ import java.util.Date;
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.junit.FailureExpected;
|
|
||||||
import org.hibernate.test.annotations.TestCase;
|
import org.hibernate.test.annotations.TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
public class MoreFetchProfileTest extends TestCase{
|
public class MoreFetchProfileTest extends TestCase {
|
||||||
|
|
||||||
@FailureExpected( jiraKey = "HHH-5233")
|
|
||||||
public void testFetchWithTwoOverrides() throws Exception {
|
public void testFetchWithTwoOverrides() throws Exception {
|
||||||
Session s = openSession( );
|
Session s = openSession();
|
||||||
s.enableFetchProfile( "customer-with-orders-and-country" );
|
s.enableFetchProfile( "customer-with-orders-and-country" );
|
||||||
final Transaction transaction = s.beginTransaction();
|
final Transaction transaction = s.beginTransaction();
|
||||||
Country ctry = new Country();
|
Country ctry = new Country();
|
||||||
|
@ -43,10 +67,10 @@ public class MoreFetchProfileTest extends TestCase{
|
||||||
|
|
||||||
s.clear();
|
s.clear();
|
||||||
|
|
||||||
c = (Customer) s.get( Customer.class, c.getId() );
|
c = ( Customer ) s.get( Customer.class, c.getId() );
|
||||||
assertTrue( Hibernate.isInitialized( c.getLastOrder() ) );
|
assertTrue( Hibernate.isInitialized( c.getLastOrder() ) );
|
||||||
assertTrue( Hibernate.isInitialized( c.getOrders() ) );
|
assertTrue( Hibernate.isInitialized( c.getOrders() ) );
|
||||||
for(Order so : c.getOrders() ) {
|
for ( Order so : c.getOrders() ) {
|
||||||
assertTrue( Hibernate.isInitialized( so.getCountry() ) );
|
assertTrue( Hibernate.isInitialized( so.getCountry() ) );
|
||||||
}
|
}
|
||||||
final Order order = c.getOrders().iterator().next();
|
final Order order = c.getOrders().iterator().next();
|
||||||
|
|
Loading…
Reference in New Issue