HHH-7074 - the replacement annotations of @Entity are not working
This commit is contained in:
parent
04b62e1a54
commit
db347c9de7
|
@ -44,12 +44,16 @@ import org.hibernate.MappingException;
|
|||
import org.hibernate.annotations.BatchSize;
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
import org.hibernate.annotations.DynamicInsert;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
import org.hibernate.annotations.Immutable;
|
||||
import org.hibernate.annotations.Loader;
|
||||
import org.hibernate.annotations.NaturalIdCache;
|
||||
import org.hibernate.annotations.OptimisticLockType;
|
||||
import org.hibernate.annotations.OptimisticLocking;
|
||||
import org.hibernate.annotations.Persister;
|
||||
import org.hibernate.annotations.Polymorphism;
|
||||
import org.hibernate.annotations.PolymorphismType;
|
||||
import org.hibernate.annotations.Proxy;
|
||||
import org.hibernate.annotations.RowId;
|
||||
|
@ -57,6 +61,7 @@ import org.hibernate.annotations.SQLDelete;
|
|||
import org.hibernate.annotations.SQLDeleteAll;
|
||||
import org.hibernate.annotations.SQLInsert;
|
||||
import org.hibernate.annotations.SQLUpdate;
|
||||
import org.hibernate.annotations.SelectBeforeUpdate;
|
||||
import org.hibernate.annotations.Subselect;
|
||||
import org.hibernate.annotations.Synchronize;
|
||||
import org.hibernate.annotations.Tables;
|
||||
|
@ -153,24 +158,48 @@ public class EntityBinder {
|
|||
bindHibernateAnnotation( hibAnn );
|
||||
}
|
||||
|
||||
@SuppressWarnings("SimplifiableConditionalExpression")
|
||||
private void bindHibernateAnnotation(org.hibernate.annotations.Entity hibAnn) {
|
||||
{
|
||||
final DynamicInsert dynamicInsertAnn = annotatedClass.getAnnotation( DynamicInsert.class );
|
||||
this.dynamicInsert = dynamicInsertAnn == null
|
||||
? ( hibAnn == null ? false : hibAnn.dynamicInsert() )
|
||||
: dynamicInsertAnn.value();
|
||||
}
|
||||
|
||||
{
|
||||
final DynamicUpdate dynamicUpdateAnn = annotatedClass.getAnnotation( DynamicUpdate.class );
|
||||
this.dynamicUpdate = dynamicUpdateAnn == null
|
||||
? ( hibAnn == null ? false : hibAnn.dynamicUpdate() )
|
||||
: dynamicUpdateAnn.value();
|
||||
}
|
||||
|
||||
{
|
||||
final SelectBeforeUpdate selectBeforeUpdateAnn = annotatedClass.getAnnotation( SelectBeforeUpdate.class );
|
||||
this.selectBeforeUpdate = selectBeforeUpdateAnn == null
|
||||
? ( hibAnn == null ? false : hibAnn.selectBeforeUpdate() )
|
||||
: selectBeforeUpdateAnn.value();
|
||||
}
|
||||
|
||||
{
|
||||
final OptimisticLocking optimisticLockingAnn = annotatedClass.getAnnotation( OptimisticLocking.class );
|
||||
this.optimisticLockType = optimisticLockingAnn == null
|
||||
? ( hibAnn == null ? OptimisticLockType.VERSION : hibAnn.optimisticLock() )
|
||||
: optimisticLockingAnn.type();
|
||||
}
|
||||
|
||||
{
|
||||
final Polymorphism polymorphismAnn = annotatedClass.getAnnotation( Polymorphism.class );
|
||||
this.polymorphismType = polymorphismAnn == null
|
||||
? ( hibAnn == null ? PolymorphismType.IMPLICIT : hibAnn.polymorphism() )
|
||||
: polymorphismAnn.type();
|
||||
}
|
||||
|
||||
if ( hibAnn != null ) {
|
||||
dynamicInsert = hibAnn.dynamicInsert();
|
||||
dynamicUpdate = hibAnn.dynamicUpdate();
|
||||
optimisticLockType = hibAnn.optimisticLock();
|
||||
selectBeforeUpdate = hibAnn.selectBeforeUpdate();
|
||||
polymorphismType = hibAnn.polymorphism();
|
||||
// used later in bind for logging
|
||||
explicitHibernateEntityAnnotation = true;
|
||||
//persister handled in bind
|
||||
}
|
||||
else {
|
||||
//default values when the annotation is not there
|
||||
dynamicInsert = false;
|
||||
dynamicUpdate = false;
|
||||
optimisticLockType = OptimisticLockType.VERSION;
|
||||
polymorphismType = PolymorphismType.IMPLICIT;
|
||||
selectBeforeUpdate = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void bindEjb3Annotation(Entity ejb3Ann) {
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2012, 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.test.annotations.entity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.annotations.DynamicInsert;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.hibernate.annotations.OptimisticLock;
|
||||
import org.hibernate.annotations.OptimisticLockType;
|
||||
import org.hibernate.annotations.OptimisticLocking;
|
||||
import org.hibernate.annotations.Polymorphism;
|
||||
import org.hibernate.annotations.PolymorphismType;
|
||||
import org.hibernate.annotations.SelectBeforeUpdate;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
/**
|
||||
* Mapping following lines of {@link Forest}, but using the replacements for the now deprecated
|
||||
* {@link org.hibernate.annotations.Entity} annotation.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@Entity
|
||||
@DynamicInsert
|
||||
@DynamicUpdate
|
||||
@SelectBeforeUpdate
|
||||
@OptimisticLocking( type = OptimisticLockType.ALL )
|
||||
@Polymorphism( type = PolymorphismType.EXPLICIT )
|
||||
public class Forest2 {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private String longDescription;
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@OptimisticLock(excluded=true)
|
||||
@Type(type = "text")
|
||||
public String getLongDescription() {
|
||||
return longDescription;
|
||||
}
|
||||
|
||||
public void setLongDescription(String longDescription) {
|
||||
this.longDescription = longDescription;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2012, 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.test.annotations.entity;
|
||||
|
||||
import org.hibernate.mapping.RootClass;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class NewCustomEntityMappingAnnotationsTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { Forest.class, Forest2.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getAnnotatedPackages() {
|
||||
return new String[] { Forest.class.getPackage().getName() };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameMappingValues() {
|
||||
RootClass forest = (RootClass) configuration().getClassMapping( Forest.class.getName() );
|
||||
RootClass forest2 = (RootClass) configuration().getClassMapping( Forest2.class.getName() );
|
||||
assertEquals( forest.useDynamicInsert(), forest2.useDynamicInsert() );
|
||||
assertEquals( forest.useDynamicUpdate(), forest2.useDynamicUpdate() );
|
||||
assertEquals( forest.hasSelectBeforeUpdate(), forest2.hasSelectBeforeUpdate() );
|
||||
assertEquals( forest.getOptimisticLockMode(), forest2.getOptimisticLockMode() );
|
||||
assertEquals( forest.isExplicitPolymorphism(), forest2.isExplicitPolymorphism() );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue