HHH-5821 - JPA EntityType's (or ManagedType's) getSingularAttributes() returns the version attribute with isVersion set to false.
This commit is contained in:
parent
d519d8c425
commit
b3967db041
|
@ -260,6 +260,7 @@ public abstract class AbstractIdentifiableType<X>
|
|||
|
||||
public void applyVersionAttribute(SingularAttributeImpl<X, ?> versionAttribute) {
|
||||
AbstractIdentifiableType.this.version = versionAttribute;
|
||||
managedBuilder.addAttribute( versionAttribute );
|
||||
}
|
||||
|
||||
public void addAttribute(Attribute<X, ?> attribute) {
|
||||
|
|
|
@ -180,6 +180,10 @@ class MetadataContext {
|
|||
// #buildIdClassAttributes
|
||||
continue;
|
||||
}
|
||||
if ( safeMapping.isVersioned() && property == safeMapping.getVersion() ) {
|
||||
// skip the version property, it was already handled previously.
|
||||
continue;
|
||||
}
|
||||
final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property );
|
||||
if ( attribute != null ) {
|
||||
jpa2Mapping.getBuilder().addAttribute( attribute );
|
||||
|
@ -205,6 +209,10 @@ class MetadataContext {
|
|||
Iterator<Property> properties = ( Iterator<Property> ) safeMapping.getDeclaredPropertyIterator();
|
||||
while ( properties.hasNext() ) {
|
||||
final Property property = properties.next();
|
||||
if ( safeMapping.isVersioned() && property == safeMapping.getVersion() ) {
|
||||
// skip the version property, it was already handled previously.
|
||||
continue;
|
||||
}
|
||||
final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property );
|
||||
if ( attribute != null ) {
|
||||
jpa2Mapping.getBuilder().addAttribute( attribute );
|
||||
|
|
|
@ -36,7 +36,7 @@ public abstract class AbstractMetamodelSpecificTest extends TestCase {
|
|||
return new Class[] {
|
||||
Address.class, Alias.class, Country.class, CreditCard.class, Customer.class,
|
||||
Info.class, LineItem.class, Order.class, Phone.class, Product.class,
|
||||
ShelfLife.class, Spouse.class
|
||||
ShelfLife.class, Spouse.class, VersionedEntity.class
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
package org.hibernate.ejb.metamodel;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.metamodel.EntityType;
|
||||
import javax.persistence.metamodel.SingularAttribute;
|
||||
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
|
@ -37,7 +38,7 @@ public class EmbeddedTypeTest extends TestCase {
|
|||
@Override
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Product.class, ShelfLife.class
|
||||
Product.class, ShelfLife.class, VersionedEntity.class
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -55,4 +56,16 @@ public class EmbeddedTypeTest extends TestCase {
|
|||
em.getTransaction().commit();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testVersionAttributeMetadata() {
|
||||
// HHH-5821
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
EntityType<VersionedEntity> metadata = em.getMetamodel().entity( VersionedEntity.class );
|
||||
assertNotNull( metadata.getDeclaredVersion( int.class ) );
|
||||
assertTrue( metadata.getDeclaredVersion( int.class ).isVersion() );
|
||||
assertEquals( 3, metadata.getDeclaredSingularAttributes().size() );
|
||||
assertTrue( metadata.getDeclaredSingularAttributes().contains( metadata.getDeclaredVersion( int.class ) ) );
|
||||
em.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.ejb.metamodel;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@Entity
|
||||
public class VersionedEntity {
|
||||
private String id;
|
||||
private String name;
|
||||
private int version;
|
||||
|
||||
@Id
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Version
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue