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
|
||||
~ 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>
|
||||
|
||||
|
@ -44,7 +46,7 @@
|
|||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>${version}</version>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
|
@ -54,12 +56,12 @@
|
|||
<groupId>org.hibernate.javax.persistence</groupId>
|
||||
<artifactId>hibernate-jpa-2.0-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${groupId}</groupId>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>hibernate-testing</artifactId>
|
||||
<version>${version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
|
@ -84,13 +86,6 @@
|
|||
|
||||
<build>
|
||||
<testResources>
|
||||
<testResource>
|
||||
<filtering>false</filtering>
|
||||
<directory>src/test/java</directory>
|
||||
<includes>
|
||||
<include>**/*.xml</include>
|
||||
</includes>
|
||||
</testResource>
|
||||
<testResource>
|
||||
<filtering>true</filtering>
|
||||
<directory>src/test/resources</directory>
|
||||
|
@ -116,17 +111,17 @@
|
|||
<configuration>
|
||||
<bytecodeInjections>
|
||||
<bytecodeInjection>
|
||||
<expression>${pom.version}</expression>
|
||||
<expression>${project.version}</expression>
|
||||
<targetMembers>
|
||||
<methodBodyReturn>
|
||||
<className>org.hibernate.cfg.annotations.Version</className>
|
||||
<methodName>getVersionString</methodName>
|
||||
</methodBodyReturn>
|
||||
<methodBodyReturn>
|
||||
<className>org.hibernate.cfg.annotations.Version</className>
|
||||
<methodName>getVersionString</methodName>
|
||||
</methodBodyReturn>
|
||||
</targetMembers>
|
||||
</bytecodeInjection>
|
||||
</bytecodeInjections>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.twdata.maven</groupId>
|
||||
<artifactId>maven-cli-plugin</artifactId>
|
||||
|
|
|
@ -163,6 +163,7 @@ public class AnnotationConfiguration extends Configuration {
|
|||
private boolean isValidatorNotPresentLogged;
|
||||
private Map<XClass, Map<String, PropertyData>> propertiesAnnotatedWithMapsId;
|
||||
private Map<XClass, Map<String, PropertyData>> propertiesAnnotatedWithIdAndToOne;
|
||||
private Collection<FetchProfile> annotationConfiguredProfiles;
|
||||
|
||||
public AnnotationConfiguration() {
|
||||
super();
|
||||
|
@ -268,7 +269,7 @@ public class AnnotationConfiguration extends Configuration {
|
|||
}
|
||||
|
||||
public ExtendedMappings createExtendedMappings() {
|
||||
return new ExtendedMappingsImpl();
|
||||
return new ExtendedMappingsImpl( annotationConfiguredProfiles );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -311,6 +312,7 @@ public class AnnotationConfiguration extends Configuration {
|
|||
reflectionManager = new JavaReflectionManager();
|
||||
( ( MetadataProviderInjector ) reflectionManager ).setMetadataProvider( new JPAMetadataProvider() );
|
||||
configurationArtefactPrecedence = Collections.emptyList();
|
||||
annotationConfiguredProfiles = new HashSet<FetchProfile>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1255,8 +1257,8 @@ public class AnnotationConfiguration extends Configuration {
|
|||
private Boolean useNewGeneratorMappings;
|
||||
private Collection<FetchProfile> annotationConfiguredProfile;
|
||||
|
||||
public ExtendedMappingsImpl() {
|
||||
annotationConfiguredProfile = new ArrayList<FetchProfile>();
|
||||
public ExtendedMappingsImpl(Collection<FetchProfile> fetchProfiles) {
|
||||
annotationConfiguredProfile = fetchProfiles;
|
||||
}
|
||||
|
||||
public void addDefaultGenerator(IdGenerator generator) {
|
||||
|
@ -1528,11 +1530,15 @@ public class AnnotationConfiguration extends Configuration {
|
|||
return anyMetaDefs.get( name );
|
||||
}
|
||||
|
||||
public void addAnnotationConfiguredFetchProfile(FetchProfile fetchProfile) {
|
||||
annotationConfiguredProfile.add( fetchProfile );
|
||||
public FetchProfile findOrCreateFetchProfile(String name) {
|
||||
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 ) {
|
||||
// we need reference equality there!!
|
||||
if ( profile == fetchProfile ) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// $Id:$
|
||||
// $Id$
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
|
@ -207,14 +207,8 @@ public interface ExtendedMappings extends Mappings {
|
|||
void addToOneAndIdProperty(XClass entity, PropertyData property);
|
||||
|
||||
/**
|
||||
* Add the specified profile to the list of fetch profiles configured via annotations.
|
||||
*
|
||||
* @param fetchProfile the fetch profile
|
||||
* @param fetchProfile The fetch profile to test.
|
||||
* @return {@code true} if the provided fetch profile has been configured via annotations, {@code false} otherwise.
|
||||
*/
|
||||
void addAnnotationConfiguredFetchProfile(FetchProfile fetchProfile);
|
||||
|
||||
/**
|
||||
* @return {@true} if the provided fetch profile has been configured via xml, {@false otherwise}.
|
||||
*/
|
||||
boolean containsAnnotationConfiguredFetchProfile(FetchProfile fetchProfile);
|
||||
boolean isAnnotationConfiguredFetchProfile(FetchProfile fetchProfile);
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
// $Id:$
|
||||
// $Id$
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
|
@ -47,7 +47,7 @@ public class VerifyFetchProfileReferenceSecondPass implements SecondPass {
|
|||
|
||||
public void doSecondPass(Map persistentClasses) throws MappingException {
|
||||
org.hibernate.mapping.FetchProfile profile = mappings.findOrCreateFetchProfile( fetchProfileName );
|
||||
if ( skipProfile( profile ) ) {
|
||||
if ( !mappings.isAnnotationConfiguredFetchProfile( profile ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -59,15 +59,6 @@ public class VerifyFetchProfileReferenceSecondPass implements SecondPass {
|
|||
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;
|
||||
|
||||
import java.util.Date;
|
||||
|
@ -5,17 +30,16 @@ import java.util.Date;
|
|||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.junit.FailureExpected;
|
||||
import org.hibernate.test.annotations.TestCase;
|
||||
|
||||
/**
|
||||
* @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 {
|
||||
Session s = openSession( );
|
||||
Session s = openSession();
|
||||
s.enableFetchProfile( "customer-with-orders-and-country" );
|
||||
final Transaction transaction = s.beginTransaction();
|
||||
Country ctry = new Country();
|
||||
|
@ -43,10 +67,10 @@ public class MoreFetchProfileTest extends TestCase{
|
|||
|
||||
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.getOrders() ) );
|
||||
for(Order so : c.getOrders() ) {
|
||||
for ( Order so : c.getOrders() ) {
|
||||
assertTrue( Hibernate.isInitialized( so.getCountry() ) );
|
||||
}
|
||||
final Order order = c.getOrders().iterator().next();
|
||||
|
@ -62,7 +86,7 @@ public class MoreFetchProfileTest extends TestCase{
|
|||
s.close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
|
|
Loading…
Reference in New Issue