Hibernate SVN: r17279 - beanvalidation/tags/v1_0_CR4.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-08-12 22:26:00 -0400 (Wed, 12 Aug 2009)
New Revision: 17279
Added:
beanvalidation/tags/v1_0_CR4/validation-api/
Log:
[maven-scm] copy for tag v1_0_CR4
Copied: beanvalidation/tags/v1_0_CR4/validation-api (from rev 17278, beanvalidation/trunk/validation-api)
15 years, 4 months
Hibernate SVN: r17277 - beanvalidation/trunk/validation-api.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-08-12 22:14:36 -0400 (Wed, 12 Aug 2009)
New Revision: 17277
Modified:
beanvalidation/trunk/validation-api/
Log:
update ignore list
Property changes on: beanvalidation/trunk/validation-api
___________________________________________________________________
Name: svn:ignore
- target
+ target
build
*.iml
*.ipr
15 years, 4 months
Hibernate SVN: r17276 - in core/trunk/entitymanager/src: test/java/org/hibernate/ejb/test/metadata and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-08-12 19:58:14 -0400 (Wed, 12 Aug 2009)
New Revision: 17276
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Address.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Room.java
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/ManagedTypeImpl.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Fridge.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/House.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java
Log:
EJB-456 add more tests on collection of elements Set List Map
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/ManagedTypeImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/ManagedTypeImpl.java 2009-08-12 22:51:01 UTC (rev 17275)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/ManagedTypeImpl.java 2009-08-12 23:58:14 UTC (rev 17276)
@@ -171,7 +171,7 @@
public <K, V> MapAttribute<X, K, V> getDeclaredMap(String name, Class<K> keyType, Class<V> valueType) {
final PluralAttribute<X,?,?> attr = declaredCollections.get( name );
final String error = "MapAttribute ";
- checkTypeForPluralAttributes( error, attr, name, valueType, PluralAttribute.CollectionType.LIST );
+ checkTypeForPluralAttributes( error, attr, name, valueType, PluralAttribute.CollectionType.MAP );
@SuppressWarnings( "unchecked")
final MapAttribute<X, K, V> result = ( MapAttribute<X, K, V> ) attr;
if ( result.getKeyJavaType() != keyType ) {
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Address.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Address.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Address.java 2009-08-12 23:58:14 UTC (rev 17276)
@@ -0,0 +1,42 @@
+package org.hibernate.ejb.test.metadata;
+
+import javax.persistence.Embeddable;
+import javax.persistence.Basic;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Embeddable
+public class Address {
+
+ private String address1;
+
+ private String address2;
+ private String city;
+
+ @Basic(optional = true)
+ public String getAddress1() {
+ return address1;
+ }
+
+ public void setAddress1(String address1) {
+ this.address1 = address1;
+ }
+
+ @Basic(optional = false)
+ public String getAddress2() {
+ return address2;
+ }
+
+ public void setAddress2(String address2) {
+ this.address2 = address2;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+}
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Fridge.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Fridge.java 2009-08-12 22:51:01 UTC (rev 17275)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Fridge.java 2009-08-12 23:58:14 UTC (rev 17276)
@@ -3,6 +3,7 @@
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
+import javax.persistence.Basic;
/**
* @author Emmanuel Bernard
@@ -24,6 +25,7 @@
this.id = id;
}
+ @Basic(optional = false)
public String getBrand() {
return brand;
}
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/House.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/House.java 2009-08-12 22:51:01 UTC (rev 17275)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/House.java 2009-08-12 23:58:14 UTC (rev 17276)
@@ -1,8 +1,15 @@
package org.hibernate.ejb.test.metadata;
import java.io.Serializable;
+import java.util.Set;
+import java.util.Map;
+import java.util.List;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
+import javax.persistence.ElementCollection;
+import javax.persistence.CollectionTable;
+import javax.persistence.MapKeyColumn;
+import javax.persistence.OrderColumn;
/**
* @author Emmanuel Bernard
@@ -10,8 +17,40 @@
@Entity
public class House {
private Key key;
- private String address1;
+ private Address address;
+ private Set<Room> rooms;
+ private Map<String, Room> roomsByName;
+ private List<Room> roomsBySize;
+ @ElementCollection
+ @OrderColumn(name = "size_order")
+ public List<Room> getRoomsBySize() {
+ return roomsBySize;
+ }
+
+ public void setRoomsBySize(List<Room> roomsBySize) {
+ this.roomsBySize = roomsBySize;
+ }
+
+ @ElementCollection
+ @MapKeyColumn(name="room_name")
+ public Map<String, Room> getRoomsByName() {
+ return roomsByName;
+ }
+
+ public void setRoomsByName(Map<String, Room> roomsByName) {
+ this.roomsByName = roomsByName;
+ }
+
+ @ElementCollection
+ public Set<Room> getRooms() {
+ return rooms;
+ }
+
+ public void setRooms(Set<Room> rooms) {
+ this.rooms = rooms;
+ }
+
@EmbeddedId
public Key getKey() {
return key;
@@ -21,12 +60,12 @@
this.key = key;
}
- public String getAddress1() {
- return address1;
+ public Address getAddress() {
+ return address;
}
- public void setAddress1(String address1) {
- this.address1 = address1;
+ public void setAddress(Address address) {
+ this.address = address;
}
public static class Key implements Serializable {
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java 2009-08-12 22:51:01 UTC (rev 17275)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java 2009-08-12 23:58:14 UTC (rev 17276)
@@ -7,6 +7,11 @@
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.Type;
import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.EmbeddableType;
+import javax.persistence.metamodel.SetAttribute;
+import javax.persistence.metamodel.PluralAttribute;
+import javax.persistence.metamodel.MapAttribute;
+import javax.persistence.metamodel.ListAttribute;
import org.hibernate.ejb.test.TestCase;
@@ -72,7 +77,9 @@
assertEquals( Bindable.BindableType.SINGULAR_ATTRIBUTE, singularAttribute.getBindableType() );
assertFalse( singularAttribute.isId() );
assertFalse( singularAttribute.isOptional() );
+ assertFalse( entityType.getDeclaredSingularAttribute( "brand", String.class ).isOptional() );
assertEquals( Integer.class, singularAttribute.getType().getJavaType() );
+ assertEquals( Type.PersistenceType.BASIC, singularAttribute.getType().getPersistenceType() );
final Attribute<? super Fridge, ?> attribute = entityType.getDeclaredAttribute( "temperature" );
assertNotNull( attribute );
assertEquals( "temperature", attribute.getName() );
@@ -90,10 +97,57 @@
}
}
assertTrue( found );
+ }
+ public void testEmbeddable() throws Exception {
+ final EntityType<House> entityType = factory.getMetamodel().entity( House.class );
+ final SingularAttribute<? super House,Address> address = entityType.getDeclaredSingularAttribute(
+ "address",
+ Address.class
+ );
+ assertNotNull( address );
+ assertEquals( Attribute.PersistentAttributeType.EMBEDDED, address.getPersistentAttributeType() );
+ assertFalse( address.isCollection() );
+ assertFalse( address.isAssociation() );
+ final EmbeddableType<Address> addressType = (EmbeddableType<Address>) address.getType();
+ assertEquals( Type.PersistenceType.EMBEDDABLE, addressType.getPersistenceType() );
+ assertEquals( 3, addressType.getDeclaredAttributes().size() );
+ assertTrue( addressType.getDeclaredSingularAttribute( "address1" ).isOptional() );
+ assertFalse( addressType.getDeclaredSingularAttribute( "address2" ).isOptional() );
+ final EmbeddableType<Address> directType = factory.getMetamodel().embeddable( Address.class );
+ assertNotNull( directType );
+ assertEquals( Type.PersistenceType.EMBEDDABLE, directType.getPersistenceType() );
}
- //TODO test embedded
+
+ public void testElementCollection() throws Exception {
+ final EntityType<House> entityType = factory.getMetamodel().entity( House.class );
+ final SetAttribute<House,Room> rooms = entityType.getDeclaredSet( "rooms", Room.class );
+ assertNotNull( rooms );
+ assertTrue( rooms.isAssociation() );
+ assertTrue( rooms.isCollection() );
+ assertEquals( Attribute.PersistentAttributeType.ELEMENT_COLLECTION, rooms.getPersistentAttributeType() );
+ assertEquals( Room.class, rooms.getBindableJavaType() );
+ assertEquals( Bindable.BindableType.PLURAL_ATTRIBUTE, rooms.getBindableType() );
+ assertEquals( Set.class, rooms.getJavaType() );
+ assertEquals( PluralAttribute.CollectionType.SET, rooms.getCollectionType() );
+ assertEquals( 3, entityType.getDeclaredCollections().size() );
+ assertEquals( Type.PersistenceType.EMBEDDABLE, rooms.getElementType().getPersistenceType() );
+
+ final MapAttribute<House,String,Room> roomsByName = entityType.getDeclaredMap(
+ "roomsByName", String.class, Room.class
+ );
+ assertNotNull( roomsByName );
+ assertEquals( String.class, roomsByName.getKeyJavaType() );
+ assertEquals( Type.PersistenceType.BASIC, roomsByName.getKeyType().getPersistenceType() );
+ assertEquals( PluralAttribute.CollectionType.MAP, roomsByName.getCollectionType() );
+
+ final ListAttribute<House,Room> roomsBySize = entityType.getDeclaredList( "roomsBySize", Room.class );
+ assertNotNull( roomsBySize );
+ assertEquals( Type.PersistenceType.EMBEDDABLE, roomsBySize.getElementType().getPersistenceType() );
+ assertEquals( PluralAttribute.CollectionType.LIST, roomsBySize.getCollectionType() );
+ }
+
//todo test plural
@Override
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Room.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Room.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Room.java 2009-08-12 23:58:14 UTC (rev 17276)
@@ -0,0 +1,29 @@
+package org.hibernate.ejb.test.metadata;
+
+import java.math.BigDecimal;
+import javax.persistence.Embeddable;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Embeddable
+public class Room {
+ private BigDecimal length;
+ private BigDecimal width;
+
+ public BigDecimal getLength() {
+ return length;
+ }
+
+ public void setLength(BigDecimal length) {
+ this.length = length;
+ }
+
+ public BigDecimal getWidth() {
+ return width;
+ }
+
+ public void setWidth(BigDecimal width) {
+ this.width = width;
+ }
+}
15 years, 4 months
Hibernate SVN: r17275 - core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-08-12 18:51:01 -0400 (Wed, 12 Aug 2009)
New Revision: 17275
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/House.java
Modified:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java
Log:
EJB-456 add more tests
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/House.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/House.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/House.java 2009-08-12 22:51:01 UTC (rev 17275)
@@ -0,0 +1,43 @@
+package org.hibernate.ejb.test.metadata;
+
+import java.io.Serializable;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class House {
+ private Key key;
+ private String address1;
+
+ @EmbeddedId
+ public Key getKey() {
+ return key;
+ }
+
+ public void setKey(Key key) {
+ this.key = key;
+ }
+
+ public String getAddress1() {
+ return address1;
+ }
+
+ public void setAddress1(String address1) {
+ this.address1 = address1;
+ }
+
+ public static class Key implements Serializable {
+ private String uuid;
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+ }
+}
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java 2009-08-12 14:55:01 UTC (rev 17274)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java 2009-08-12 22:51:01 UTC (rev 17275)
@@ -6,6 +6,7 @@
import javax.persistence.metamodel.Bindable;
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.Type;
+import javax.persistence.metamodel.Attribute;
import org.hibernate.ejb.test.TestCase;
@@ -37,7 +38,13 @@
assertFalse( fridgeType.hasVersionAttribute() );
assertEquals( Type.PersistenceType.ENTITY, fridgeType.getPersistenceType() );
- //TODO IdClass
+ final EntityType<House> houseType = factory.getMetamodel().entity( House.class );
+ assertTrue( houseType.hasSingleIdAttribute() );
+ final SingularAttribute<House, House.Key> houseId = houseType.getDeclaredId( House.Key.class );
+ assertNotNull( houseId );
+ assertTrue( houseId.isId() );
+ assertEquals( Attribute.PersistentAttributeType.EMBEDDED, houseId.getPersistentAttributeType() );
+
final EntityType<Person> personType = factory.getMetamodel().entity( Person.class );
assertFalse( personType.hasSingleIdAttribute() );
final Set<SingularAttribute<? super Person,?>> ids = personType.getIdClassAttributes();
@@ -63,17 +70,39 @@
);
assertEquals( Integer.class, singularAttribute.getBindableJavaType() );
assertEquals( Bindable.BindableType.SINGULAR_ATTRIBUTE, singularAttribute.getBindableType() );
+ assertFalse( singularAttribute.isId() );
+ assertFalse( singularAttribute.isOptional() );
+ assertEquals( Integer.class, singularAttribute.getType().getJavaType() );
+ final Attribute<? super Fridge, ?> attribute = entityType.getDeclaredAttribute( "temperature" );
+ assertNotNull( attribute );
+ assertEquals( "temperature", attribute.getName() );
+ assertEquals( Fridge.class, attribute.getDeclaringType().getJavaType() );
+ assertEquals( Attribute.PersistentAttributeType.BASIC, attribute.getPersistentAttributeType() );
+ assertEquals( Integer.class, attribute.getJavaType() );
+ assertFalse( attribute.isAssociation() );
+ assertFalse( attribute.isCollection() );
+ boolean found = false;
+ for (Attribute<Fridge, ?> attr : entityType.getDeclaredAttributes() ) {
+ if ("temperature".equals( attr.getName() ) ) {
+ found = true;
+ break;
+ }
+ }
+ assertTrue( found );
+
+
+ }
//TODO test embedded
//todo test plural
- }
@Override
public Class[] getAnnotatedClasses() {
return new Class[]{
Fridge.class,
FoodItem.class,
- Person.class
+ Person.class,
+ House.class
};
}
15 years, 4 months
Hibernate SVN: r17274 - in core/branches/envers-hibernate-3.3/src: test/java/org/hibernate/envers/test/integration/components and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-08-12 10:55:01 -0400 (Wed, 12 Aug 2009)
New Revision: 17274
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/MultiPropertyMapper.java
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/components/Components.java
Log:
svn merge -r 17248:17273 https://svn.jboss.org/repos/hibernate/core/trunk/envers .
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java 2009-08-12 14:49:55 UTC (rev 17273)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java 2009-08-12 14:55:01 UTC (rev 17274)
@@ -43,7 +43,7 @@
*/
public class ComponentPropertyMapper implements PropertyMapper, CompositeMapperBuilder {
private final PropertyData propertyData;
- private final ExtendedPropertyMapper delegate;
+ private final MultiPropertyMapper delegate;
private final String componentClassName;
public ComponentPropertyMapper(PropertyData propertyData, String componentClassName) {
@@ -75,14 +75,26 @@
Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyData);
- try {
- Object subObj = ReflectHelper.getDefaultConstructor(
- Thread.currentThread().getContextClassLoader().loadClass(componentClassName)).newInstance();
- setter.set(obj, subObj, null);
- delegate.mapToEntityFromMap(verCfg, subObj, data, primaryKey, versionsReader, revision);
- } catch (Exception e) {
- throw new AuditException(e);
- }
+ // If all properties are null and single, then the component has to be null also.
+ boolean allNullAndSingle = true;
+ for (Map.Entry<PropertyData, PropertyMapper> property : delegate.getProperties().entrySet()) {
+ if (data.get(property.getKey().getName()) != null || !(property.getValue() instanceof SinglePropertyMapper)) {
+ allNullAndSingle = false;
+ break;
+ }
+ }
+
+ // And we don't have to set anything on the object - the default value is null
+ if (!allNullAndSingle) {
+ try {
+ Object subObj = ReflectHelper.getDefaultConstructor(
+ Thread.currentThread().getContextClassLoader().loadClass(componentClassName)).newInstance();
+ setter.set(obj, subObj, null);
+ delegate.mapToEntityFromMap(verCfg, subObj, data, primaryKey, versionsReader, revision);
+ } catch (Exception e) {
+ throw new AuditException(e);
+ }
+ }
}
public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/MultiPropertyMapper.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/MultiPropertyMapper.java 2009-08-12 14:49:55 UTC (rev 17273)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/MultiPropertyMapper.java 2009-08-12 14:55:01 UTC (rev 17274)
@@ -26,6 +26,7 @@
import java.io.Serializable;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.hibernate.envers.entities.PropertyData;
import org.hibernate.envers.configuration.AuditConfiguration;
@@ -150,4 +151,8 @@
return null;
}
}
+
+ public Map<PropertyData, PropertyMapper> getProperties() {
+ return properties;
+ }
}
Modified: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/components/Components.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/components/Components.java 2009-08-12 14:49:55 UTC (rev 17273)
+++ core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/components/Components.java 2009-08-12 14:55:01 UTC (rev 17274)
@@ -42,6 +42,7 @@
private Integer id1;
private Integer id2;
private Integer id3;
+ private Integer id4;
public void configure(Ejb3Configuration cfg) {
cfg.addAnnotatedClass(ComponentTestEntity.class);
@@ -56,10 +57,12 @@
ComponentTestEntity cte1 = new ComponentTestEntity(new Component1("a", "b"), new Component2("x", "y"));
ComponentTestEntity cte2 = new ComponentTestEntity(new Component1("a2", "b2"), new Component2("x2", "y2"));
ComponentTestEntity cte3 = new ComponentTestEntity(new Component1("a3", "b3"), new Component2("x3", "y3"));
+ ComponentTestEntity cte4 = new ComponentTestEntity(null, null);
em.persist(cte1);
em.persist(cte2);
em.persist(cte3);
+ em.persist(cte4);
em.getTransaction().commit();
@@ -70,10 +73,15 @@
cte1 = em.find(ComponentTestEntity.class, cte1.getId());
cte2 = em.find(ComponentTestEntity.class, cte2.getId());
cte3 = em.find(ComponentTestEntity.class, cte3.getId());
+ cte4 = em.find(ComponentTestEntity.class, cte4.getId());
cte1.setComp1(new Component1("a'", "b'"));
cte2.getComp1().setStr1("a2'");
cte3.getComp2().setStr6("y3'");
+ cte4.setComp1(new Component1());
+ cte4.getComp1().setStr1("n");
+ cte4.setComp2(new Component2());
+ cte4.getComp2().setStr5("m");
em.getTransaction().commit();
@@ -84,9 +92,12 @@
cte1 = em.find(ComponentTestEntity.class, cte1.getId());
cte2 = em.find(ComponentTestEntity.class, cte2.getId());
cte3 = em.find(ComponentTestEntity.class, cte3.getId());
+ cte4 = em.find(ComponentTestEntity.class, cte4.getId());
cte1.setComp2(new Component2("x'", "y'"));
cte3.getComp1().setStr2("b3'");
+ cte4.setComp1(null);
+ cte4.setComp2(null);
em.getTransaction().commit();
@@ -103,6 +114,7 @@
id1 = cte1.getId();
id2 = cte2.getId();
id3 = cte3.getId();
+ id4 = cte4.getId();
}
@Test
@@ -112,6 +124,8 @@
assert Arrays.asList(1, 2, 4).equals(getAuditReader().getRevisions(ComponentTestEntity.class, id2));
assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(ComponentTestEntity.class, id3));
+
+ assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(ComponentTestEntity.class, id4));
}
@Test
@@ -146,4 +160,16 @@
assert getAuditReader().find(ComponentTestEntity.class, id3, 3).equals(ver2);
assert getAuditReader().find(ComponentTestEntity.class, id3, 4).equals(ver2);
}
+
+ @Test
+ public void testHistoryOfId4() {
+ ComponentTestEntity ver1 = new ComponentTestEntity(id4, null, null);
+ ComponentTestEntity ver2 = new ComponentTestEntity(id4, new Component1("n", null), null);
+ ComponentTestEntity ver3 = new ComponentTestEntity(id4, null, null);
+
+ assert getAuditReader().find(ComponentTestEntity.class, id4, 1).equals(ver1);
+ assert getAuditReader().find(ComponentTestEntity.class, id4, 2).equals(ver2);
+ assert getAuditReader().find(ComponentTestEntity.class, id4, 3).equals(ver3);
+ assert getAuditReader().find(ComponentTestEntity.class, id4, 4).equals(ver3);
+ }
}
15 years, 4 months
Hibernate SVN: r17273 - in core/trunk/envers/src: test/java/org/hibernate/envers/test/integration/components and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-08-12 10:49:55 -0400 (Wed, 12 Aug 2009)
New Revision: 17273
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/MultiPropertyMapper.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/components/Components.java
Log:
HHH-3957:
- when all properties of an embedded object are null, don't set the embedded object on the entity
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java 2009-08-12 04:22:23 UTC (rev 17272)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java 2009-08-12 14:49:55 UTC (rev 17273)
@@ -43,7 +43,7 @@
*/
public class ComponentPropertyMapper implements PropertyMapper, CompositeMapperBuilder {
private final PropertyData propertyData;
- private final ExtendedPropertyMapper delegate;
+ private final MultiPropertyMapper delegate;
private final String componentClassName;
public ComponentPropertyMapper(PropertyData propertyData, String componentClassName) {
@@ -75,14 +75,26 @@
Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyData);
- try {
- Object subObj = ReflectHelper.getDefaultConstructor(
- Thread.currentThread().getContextClassLoader().loadClass(componentClassName)).newInstance();
- setter.set(obj, subObj, null);
- delegate.mapToEntityFromMap(verCfg, subObj, data, primaryKey, versionsReader, revision);
- } catch (Exception e) {
- throw new AuditException(e);
- }
+ // If all properties are null and single, then the component has to be null also.
+ boolean allNullAndSingle = true;
+ for (Map.Entry<PropertyData, PropertyMapper> property : delegate.getProperties().entrySet()) {
+ if (data.get(property.getKey().getName()) != null || !(property.getValue() instanceof SinglePropertyMapper)) {
+ allNullAndSingle = false;
+ break;
+ }
+ }
+
+ // And we don't have to set anything on the object - the default value is null
+ if (!allNullAndSingle) {
+ try {
+ Object subObj = ReflectHelper.getDefaultConstructor(
+ Thread.currentThread().getContextClassLoader().loadClass(componentClassName)).newInstance();
+ setter.set(obj, subObj, null);
+ delegate.mapToEntityFromMap(verCfg, subObj, data, primaryKey, versionsReader, revision);
+ } catch (Exception e) {
+ throw new AuditException(e);
+ }
+ }
}
public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/MultiPropertyMapper.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/MultiPropertyMapper.java 2009-08-12 04:22:23 UTC (rev 17272)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/MultiPropertyMapper.java 2009-08-12 14:49:55 UTC (rev 17273)
@@ -26,6 +26,7 @@
import java.io.Serializable;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.hibernate.envers.entities.PropertyData;
import org.hibernate.envers.configuration.AuditConfiguration;
@@ -150,4 +151,8 @@
return null;
}
}
+
+ public Map<PropertyData, PropertyMapper> getProperties() {
+ return properties;
+ }
}
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/components/Components.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/components/Components.java 2009-08-12 04:22:23 UTC (rev 17272)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/components/Components.java 2009-08-12 14:49:55 UTC (rev 17273)
@@ -42,6 +42,7 @@
private Integer id1;
private Integer id2;
private Integer id3;
+ private Integer id4;
public void configure(Ejb3Configuration cfg) {
cfg.addAnnotatedClass(ComponentTestEntity.class);
@@ -56,10 +57,12 @@
ComponentTestEntity cte1 = new ComponentTestEntity(new Component1("a", "b"), new Component2("x", "y"));
ComponentTestEntity cte2 = new ComponentTestEntity(new Component1("a2", "b2"), new Component2("x2", "y2"));
ComponentTestEntity cte3 = new ComponentTestEntity(new Component1("a3", "b3"), new Component2("x3", "y3"));
+ ComponentTestEntity cte4 = new ComponentTestEntity(null, null);
em.persist(cte1);
em.persist(cte2);
em.persist(cte3);
+ em.persist(cte4);
em.getTransaction().commit();
@@ -70,10 +73,15 @@
cte1 = em.find(ComponentTestEntity.class, cte1.getId());
cte2 = em.find(ComponentTestEntity.class, cte2.getId());
cte3 = em.find(ComponentTestEntity.class, cte3.getId());
+ cte4 = em.find(ComponentTestEntity.class, cte4.getId());
cte1.setComp1(new Component1("a'", "b'"));
cte2.getComp1().setStr1("a2'");
cte3.getComp2().setStr6("y3'");
+ cte4.setComp1(new Component1());
+ cte4.getComp1().setStr1("n");
+ cte4.setComp2(new Component2());
+ cte4.getComp2().setStr5("m");
em.getTransaction().commit();
@@ -84,9 +92,12 @@
cte1 = em.find(ComponentTestEntity.class, cte1.getId());
cte2 = em.find(ComponentTestEntity.class, cte2.getId());
cte3 = em.find(ComponentTestEntity.class, cte3.getId());
+ cte4 = em.find(ComponentTestEntity.class, cte4.getId());
cte1.setComp2(new Component2("x'", "y'"));
cte3.getComp1().setStr2("b3'");
+ cte4.setComp1(null);
+ cte4.setComp2(null);
em.getTransaction().commit();
@@ -103,6 +114,7 @@
id1 = cte1.getId();
id2 = cte2.getId();
id3 = cte3.getId();
+ id4 = cte4.getId();
}
@Test
@@ -112,6 +124,8 @@
assert Arrays.asList(1, 2, 4).equals(getAuditReader().getRevisions(ComponentTestEntity.class, id2));
assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(ComponentTestEntity.class, id3));
+
+ assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(ComponentTestEntity.class, id4));
}
@Test
@@ -146,4 +160,16 @@
assert getAuditReader().find(ComponentTestEntity.class, id3, 3).equals(ver2);
assert getAuditReader().find(ComponentTestEntity.class, id3, 4).equals(ver2);
}
+
+ @Test
+ public void testHistoryOfId4() {
+ ComponentTestEntity ver1 = new ComponentTestEntity(id4, null, null);
+ ComponentTestEntity ver2 = new ComponentTestEntity(id4, new Component1("n", null), null);
+ ComponentTestEntity ver3 = new ComponentTestEntity(id4, null, null);
+
+ assert getAuditReader().find(ComponentTestEntity.class, id4, 1).equals(ver1);
+ assert getAuditReader().find(ComponentTestEntity.class, id4, 2).equals(ver2);
+ assert getAuditReader().find(ComponentTestEntity.class, id4, 3).equals(ver3);
+ assert getAuditReader().find(ComponentTestEntity.class, id4, 4).equals(ver3);
+ }
}
15 years, 4 months
Hibernate SVN: r17272 - in core/trunk/entitymanager/src: test/java/org/hibernate/ejb/test/metadata and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-08-12 00:22:23 -0400 (Wed, 12 Aug 2009)
New Revision: 17272
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Person.java
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelFactory.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/FoodItem.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java
Log:
EJB-456 add more test and fix isId false on IdClass attributes
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeImpl.java 2009-08-12 03:05:57 UTC (rev 17271)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeImpl.java 2009-08-12 04:22:23 UTC (rev 17272)
@@ -94,7 +94,7 @@
Set<SingularAttribute<? super X, ?>> attributes = new HashSet<SingularAttribute<? super X, ?>>();
while ( properties.hasNext() ) {
attributes.add(
- (SingularAttribute<? super X, ?>) MetamodelFactory.getAttribute( this, properties.next(), context )
+ (SingularAttribute<? super X, ?>) MetamodelFactory.getAttribute( this, properties.next(), context, true )
);
}
return attributes;
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelFactory.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelFactory.java 2009-08-12 03:05:57 UTC (rev 17271)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelFactory.java 2009-08-12 04:22:23 UTC (rev 17272)
@@ -20,6 +20,10 @@
class MetamodelFactory {
static<X, Y, V, K> Attribute<X, Y> getAttribute(ManagedType<X> ownerType, Property property, MetadataContext metadataContext) {
+ return getAttribute( ownerType, property, metadataContext, false );
+ }
+
+ static<X, Y, V, K> Attribute<X, Y> getAttribute(ManagedType<X> ownerType, Property property, MetadataContext metadataContext, boolean isId) {
AttributeContext attrContext = getAttributeContext( property );
final Attribute<X, Y> attribute;
if ( attrContext.isCollection() ) {
@@ -44,11 +48,12 @@
}
else {
final Type<Y> attrType = getType( attrContext.getElementTypeStatus(), attrContext.getElementValue(), metadataContext );
- attribute = SingularAttributeImpl.create( ownerType, attrType )
+ final SingularAttributeImpl.Builder<X, Y> xyBuilder = SingularAttributeImpl.create( ownerType, attrType )
// .member( ); //TODO member
.property( property )
- .persistentAttributeType( attrContext.getElementAttributeType() )
- .build();
+ .persistentAttributeType( attrContext.getElementAttributeType() );
+ if (isId) xyBuilder.id();
+ attribute = xyBuilder.build();
}
return attribute;
}
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/FoodItem.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/FoodItem.java 2009-08-12 03:05:57 UTC (rev 17271)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/FoodItem.java 2009-08-12 04:22:23 UTC (rev 17272)
@@ -3,6 +3,7 @@
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
+import javax.persistence.Version;
/**
* @author Emmanuel Bernard
@@ -11,6 +12,7 @@
public class FoodItem {
private Long id;
private String name;
+ private Long version;
@Id @GeneratedValue
public Long getId() {
@@ -21,6 +23,15 @@
this.id = id;
}
+ @Version
+ public Long getVersion() {
+ return version;
+ }
+
+ public void setVersion(Long version) {
+ this.version = version;
+ }
+
public String getName() {
return name;
}
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java 2009-08-12 03:05:57 UTC (rev 17271)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java 2009-08-12 04:22:23 UTC (rev 17272)
@@ -1,9 +1,11 @@
package org.hibernate.ejb.test.metadata;
+import java.util.Set;
import javax.persistence.EntityManagerFactory;
import javax.persistence.metamodel.EntityType;
import javax.persistence.metamodel.Bindable;
import javax.persistence.metamodel.SingularAttribute;
+import javax.persistence.metamodel.Type;
import org.hibernate.ejb.test.TestCase;
@@ -19,11 +21,42 @@
assertNotNull( entityType );
}
- public void testBindable() throws Exception {
- EntityManagerFactory emf = factory;
- final EntityType<Fridge> entityType = emf.getMetamodel().entity( Fridge.class );
- assertEquals( Fridge.class, entityType.getBindableJavaType() );
- assertEquals( Bindable.BindableType.ENTITY_TYPE, entityType.getBindableType() );
+ public void testEntity() throws Exception {
+ final EntityType<Fridge> fridgeType = factory.getMetamodel().entity( Fridge.class );
+ assertEquals( Fridge.class, fridgeType.getBindableJavaType() );
+ assertEquals( Bindable.BindableType.ENTITY_TYPE, fridgeType.getBindableType() );
+ assertNotNull( fridgeType.getDeclaredSingularAttribute( "temperature", Integer.class ) );
+ assertNotNull( fridgeType.getDeclaredSingularAttribute( "temperature" ) );
+ assertNotNull( fridgeType.getDeclaredAttribute( "temperature" ) );
+ final SingularAttribute<Fridge, Long> id = fridgeType.getDeclaredId( Long.class );
+ assertNotNull( id );
+ assertTrue( id.isId() );
+ assertEquals( Fridge.class.getName(), fridgeType.getName() );
+ assertEquals( Long.class, fridgeType.getIdType().getJavaType() );
+ assertTrue( fridgeType.hasSingleIdAttribute() );
+ assertFalse( fridgeType.hasVersionAttribute() );
+ assertEquals( Type.PersistenceType.ENTITY, fridgeType.getPersistenceType() );
+
+ //TODO IdClass
+ final EntityType<Person> personType = factory.getMetamodel().entity( Person.class );
+ assertFalse( personType.hasSingleIdAttribute() );
+ final Set<SingularAttribute<? super Person,?>> ids = personType.getIdClassAttributes();
+ assertNotNull( ids );
+ assertEquals( 2, ids.size() );
+ for (SingularAttribute<? super Person,?> localId : ids) {
+ assertTrue( localId.isId() );
+ }
+
+ final EntityType<FoodItem> foodType = factory.getMetamodel().entity( FoodItem.class );
+ assertTrue( foodType.hasVersionAttribute() );
+ final SingularAttribute<? super FoodItem, Long> version = foodType.getVersion( Long.class );
+ assertNotNull( version );
+ assertTrue( version.isVersion() );
+
+ }
+
+ public void testBasic() throws Exception {
+ final EntityType<Fridge> entityType = factory.getMetamodel().entity( Fridge.class );
final SingularAttribute<? super Fridge,Integer> singularAttribute = entityType.getDeclaredSingularAttribute(
"temperature",
Integer.class
@@ -39,7 +72,8 @@
public Class[] getAnnotatedClasses() {
return new Class[]{
Fridge.class,
- FoodItem.class
+ FoodItem.class,
+ Person.class
};
}
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Person.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Person.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Person.java 2009-08-12 04:22:23 UTC (rev 17272)
@@ -0,0 +1,94 @@
+package org.hibernate.ejb.test.metadata;
+
+import java.io.Serializable;
+import javax.persistence.Id;
+import javax.persistence.IdClass;
+import javax.persistence.Entity;
+
+/**
+ * @author Emmanuel Bernard
+ */
+(a)IdClass(Person.PersonPK.class)
+@Entity
+public class Person {
+ private String firstName;
+ private String lastName;
+ private Short age;
+
+ @Id
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ @Id
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public Short getAge() {
+ return age;
+ }
+
+ public void setAge(Short age) {
+ this.age = age;
+ }
+
+ public static class PersonPK implements Serializable {
+ private String firstName;
+ private String lastName;
+
+ @Id
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ @Id
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+
+ PersonPK personPK = ( PersonPK ) o;
+
+ if ( firstName != null ? !firstName.equals( personPK.firstName ) : personPK.firstName != null ) {
+ return false;
+ }
+ if ( lastName != null ? !lastName.equals( personPK.lastName ) : personPK.lastName != null ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = firstName != null ? firstName.hashCode() : 0;
+ result = 31 * result + ( lastName != null ? lastName.hashCode() : 0 );
+ return result;
+ }
+ }
+}
15 years, 4 months