Skip to content

Commit

Permalink
Merge branch '3.6' of github.com:hibernate/hibernate-core into 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
hferentschik committed Jan 3, 2011
2 parents 15607fd + f3feba6 commit 6b635a1
Show file tree
Hide file tree
Showing 22 changed files with 450 additions and 77 deletions.
Expand Up @@ -50,12 +50,12 @@ private CacheHelper() {

public static void initInternalEvict(CacheAdapter cacheAdapter, AddressAdapter member) {
EvictAll eKey = new EvictAll(member == null ? NoAddress.INSTANCE : member);
cacheAdapter.withFlags(FlagAdapter.CACHE_MODE_LOCAL).put(eKey, Internal.INIT);
cacheAdapter.withFlags(FlagAdapter.CACHE_MODE_LOCAL, FlagAdapter.SKIP_CACHE_LOAD).put(eKey, Internal.INIT);
}

public static void sendEvictAllNotification(CacheAdapter cacheAdapter, AddressAdapter member) {
EvictAll eKey = new EvictAll(member == null ? NoAddress.INSTANCE : member);
cacheAdapter.put(eKey, Internal.EVICT);
cacheAdapter.withFlags(FlagAdapter.SKIP_CACHE_LOAD).put(eKey, Internal.EVICT);
}

public static boolean isEvictAllNotification(Object key) {
Expand Down
Expand Up @@ -36,7 +36,8 @@ public enum FlagAdapter {
CACHE_MODE_LOCAL,
FORCE_ASYNCHRONOUS,
FORCE_SYNCHRONOUS,
SKIP_CACHE_STORE;
SKIP_CACHE_STORE,
SKIP_CACHE_LOAD;

Flag toFlag() {
switch(this) {
Expand All @@ -50,6 +51,8 @@ Flag toFlag() {
return Flag.FORCE_SYNCHRONOUS;
case SKIP_CACHE_STORE:
return Flag.SKIP_CACHE_STORE;
case SKIP_CACHE_LOAD:
return Flag.SKIP_CACHE_LOAD;
default:
throw new CacheException("Unmatched Infinispan flag " + this);
}
Expand Down
Expand Up @@ -346,9 +346,19 @@ private Object mergeTransientEntity(
Object propertyFromEntity = persister.getPropertyValue( entity, propertyName, source.getEntityMode() );
Type propertyType = persister.getPropertyType( propertyName );
EntityEntry copyEntry = source.getPersistenceContext().getEntry( copy );
if ( propertyFromCopy == null || ! propertyType.isEntityType() ) {
log.trace( "property '" + copyEntry.getEntityName() + "." + propertyName +
"' is null or not an entity; " + propertyName + " =["+propertyFromCopy+"]");
if ( propertyFromCopy == null ||
propertyFromEntity == null ||
! propertyType.isEntityType() ||
! copyCache.containsKey( propertyFromEntity ) ) {
if ( log.isTraceEnabled() ) {
String fullPropertyName = "property '" + copyEntry.getEntityName() + "." + propertyName;
log.trace( fullPropertyName + " in copy is " + ( propertyFromCopy == null ? "null" : propertyFromCopy ) );
log.trace( fullPropertyName + " in original is " + ( propertyFromCopy == null ? "null" : propertyFromCopy ) );
log.trace( fullPropertyName + ( propertyType.isEntityType() ? " is" : " is not" ) + " an entity type" );
if ( propertyFromEntity != null && ! copyCache.containsKey( propertyFromEntity ) ) {
log.trace( fullPropertyName + " is not in copy cache" );
}
}
if ( isNullabilityCheckedGlobal( source ) ) {
throw ex;
}
Expand All @@ -358,28 +368,18 @@ private Object mergeTransientEntity(
saveTransientEntity( copy, entityName, requestedId, source, copyCache, false );
}
}
if ( ! copyCache.containsKey( propertyFromEntity ) ) {
log.trace( "property '" + copyEntry.getEntityName() + "." + propertyName +
"' from original entity is not in copyCache; " + propertyName + " =["+propertyFromEntity+"]");
if ( isNullabilityCheckedGlobal( source ) ) {
throw ex;
if ( log.isTraceEnabled() && propertyFromEntity != null ) {
if ( ( ( EventCache ) copyCache ).isOperatedOn( propertyFromEntity ) ) {
log.trace( "property '" + copyEntry.getEntityName() + "." + propertyName +
"' from original entity is in copyCache and is in the process of being merged; " +
propertyName + " =["+propertyFromEntity+"]");
}
else {
// retry save w/o checking non-nullable properties
// (the failure will be detected later)
saveTransientEntity( copy, entityName, requestedId, source, copyCache, false );
log.trace( "property '" + copyEntry.getEntityName() + "." + propertyName +
"' from original entity is in copyCache and is not in the process of being merged; " +
propertyName + " =["+propertyFromEntity+"]");
}
}
if ( ( ( EventCache ) copyCache ).isOperatedOn( propertyFromEntity ) ) {
log.trace( "property '" + copyEntry.getEntityName() + "." + propertyName +
"' from original entity is in copyCache and is in the process of being merged; " +
propertyName + " =["+propertyFromEntity+"]");
}
else {
log.trace( "property '" + copyEntry.getEntityName() + "." + propertyName +
"' from original entity is in copyCache and is not in the process of being merged; " +
propertyName + " =["+propertyFromEntity+"]");
}
// continue...; we'll find out if it ends up not getting saved later
}

Expand Down
1 change: 0 additions & 1 deletion envers/src/main/java/org/hibernate/envers/tools/Tools.java
Expand Up @@ -82,7 +82,6 @@ public static Object getTargetFromProxy(SessionFactoryImplementor sessionFactory
proxy.getHibernateLazyInitializer().getEntityName(),
proxy.getHibernateLazyInitializer().getIdentifier()
);
proxy.getHibernateLazyInitializer().setImplementation( target );
return target;
}
finally {
Expand Down
@@ -0,0 +1,99 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, 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.envers.test.integration.proxy;

import javax.persistence.EntityManager;

import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.envers.test.AbstractEntityTest;
import org.hibernate.envers.test.entities.onetomany.ListRefEdEntity;
import org.hibernate.envers.test.entities.onetomany.ListRefIngEntity;
import org.hibernate.proxy.HibernateProxy;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

/**
* Test case for HHH-5750: Proxied objects lose the temporary session used to
* initialize them.
*
* @author Erik-Berndt Scheper
*
*/
public class AuditedCollectionProxyTest extends AbstractEntityTest {

Integer id_ListRefEdEntity1;

public void configure(Ejb3Configuration cfg) {
cfg.addAnnotatedClass(ListRefEdEntity.class);
cfg.addAnnotatedClass(ListRefIngEntity.class);
}

@BeforeClass(dependsOnMethods = "init")
public void initData() {
EntityManager em = getEntityManager();

ListRefEdEntity listReferencedEntity1 = new ListRefEdEntity(
Integer.valueOf(1), "str1");
ListRefIngEntity refingEntity1 = new ListRefIngEntity(
Integer.valueOf(1), "refing1", listReferencedEntity1);

// Revision 1
em.getTransaction().begin();
em.persist(listReferencedEntity1);
em.persist(refingEntity1);
em.getTransaction().commit();

id_ListRefEdEntity1 = listReferencedEntity1.getId();

// Revision 2
ListRefIngEntity refingEntity2 = new ListRefIngEntity(
Integer.valueOf(2), "refing2", listReferencedEntity1);

em.getTransaction().begin();
em.persist(refingEntity2);
em.getTransaction().commit();
}

@Test
public void testProxyIdentifier() {
EntityManager em = getEntityManager();

ListRefEdEntity listReferencedEntity1 = em.getReference(
ListRefEdEntity.class, id_ListRefEdEntity1);

assert listReferencedEntity1 instanceof HibernateProxy;

// Revision 3
ListRefIngEntity refingEntity3 = new ListRefIngEntity(
Integer.valueOf(3), "refing3", listReferencedEntity1);

em.getTransaction().begin();
em.persist(refingEntity3);
em.getTransaction().commit();

listReferencedEntity1.getReffering().size();

}

}
Expand Up @@ -16,15 +16,21 @@
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Table;

public class Classes {

@Embeddable
@Table(name="Edition")
public static class Edition<T> {
T name;
}


@Entity
@Table(name="Book")
public static class Book {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
Expand All @@ -35,12 +41,15 @@ public static class Book {
}

@Entity
@Table(name="PopularBook")
public static class PopularBook {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
Long id;

@ElementCollection
@JoinTable(name="PopularBook_Editions",joinColumns={@JoinColumn(name="PopularBook_id")})

Set<Edition<String>> editions = new HashSet<Edition<String>>();
}
}
Expand Up @@ -52,24 +52,24 @@ public Staff(double sizeInInches, double radius, double diameter, Integer id) {
@Column(name="size_in_cm")
@ColumnTransformer(
forColumn = "size_in_cm",
read = "size_in_cm / 2.54",
write = "? * 2.54" )
read = "size_in_cm / 2.54E0",
write = "? * 2.54E0" )
public double getSizeInInches() { return sizeInInches; }
public void setSizeInInches(double sizeInInches) { this.sizeInInches = sizeInInches; }
private double sizeInInches;

//Weird extra S to avoid potential SQL keywords
@ColumnTransformer(
read = "radiusS / 2.54",
write = "? * 2.54" )
read = "radiusS / 2.54E0",
write = "? * 2.54E0" )
public double getRadiusS() { return radiusS; }
public void setRadiusS(double radiusS) { this.radiusS = radiusS; }
private double radiusS;

@Column(name="diamet")
@ColumnTransformer(
read = "diamet / 2.54",
write = "? * 2.54" )
read = "diamet / 2.54E0",
write = "? * 2.54E0" )
public double getDiameter() { return diameter; }
public void setDiameter(double diameter) { this.diameter = diameter; }
private double diameter;
Expand Down
@@ -0,0 +1,52 @@
/*
* 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.cascade.circle;

import junit.framework.Test;

import org.hibernate.TransientObjectException;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;

/**
* @author Gail Badner
*/
public class MultiPathCircleCascadeCheckNullFalseDelayedInsertTest extends MultiPathCircleCascadeDelayedInsertTest {

public MultiPathCircleCascadeCheckNullFalseDelayedInsertTest(String str) {
super( str );
}

@Override
public void configure(Configuration cfg) {
super.configure( cfg );
cfg.setProperty( Environment.CHECK_NULLABILITY, "false" );
}

public static Test suite() {
return new FunctionalTestClassTestSuite( MultiPathCircleCascadeCheckNullFalseDelayedInsertTest.class );
}
}
@@ -0,0 +1,51 @@
/*
* 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.cascade.circle;

import junit.framework.Test;

import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;

/**
* @author Gail Badner
*/
public class MultiPathCircleCascadeCheckNullTrueDelayedInsertTest extends MultiPathCircleCascadeDelayedInsertTest {

public MultiPathCircleCascadeCheckNullTrueDelayedInsertTest(String str) {
super( str );
}

@Override
public void configure(Configuration cfg) {
super.configure( cfg );
cfg.setProperty( Environment.CHECK_NULLABILITY, "true" );
}

public static Test suite() {
return new FunctionalTestClassTestSuite( MultiPathCircleCascadeCheckNullTrueDelayedInsertTest.class );
}
}

0 comments on commit 6b635a1

Please sign in to comment.