Added regression test for HHH-9327

(cherry picked from commit 3da903f064)
(cherry picked from commit 1df6c45f8a)
This commit is contained in:
Christian Beikov 2014-08-19 03:12:41 +02:00 committed by Gail Badner
parent 35edd56907
commit 4505843f02
4 changed files with 295 additions and 0 deletions

View File

@ -0,0 +1,110 @@
/*
* 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.test.namingstrategy.regression;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Embeddable;
@Embeddable
public class LocalizedEntity implements Serializable, Cloneable {
private static final long serialVersionUID = -8539302606114365372L;
private String name;
private String description;
/**
* Empty Constructor
*/
public LocalizedEntity() {
super();
}
/**
* @param name
* @param description
*/
public LocalizedEntity(String name, String description) {
super();
this.name = name;
this.description = description;
}
@Column(name = "NAME", nullable = false, length = 255)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "DESCRIPTION", nullable = false, length = 2500)
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public LocalizedEntity clone() {
return new LocalizedEntity( this.name, this.description );
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ( ( description == null ) ? 0 : description.hashCode() );
result = prime * result + ( ( name == null ) ? 0 : name.hashCode() );
return result;
}
@Override
public boolean equals(Object obj) {
if ( this == obj )
return true;
if ( obj == null )
return false;
if ( getClass() != obj.getClass() )
return false;
LocalizedEntity other = (LocalizedEntity) obj;
if ( description == null ) {
if ( other.description != null )
return false;
}
else if ( !description.equals( other.description ) )
return false;
if ( name == null ) {
if ( other.name != null )
return false;
}
else if ( !name.equals( other.name ) )
return false;
return true;
}
}

View File

@ -0,0 +1,47 @@
/*
* 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.test.namingstrategy.regression;
import org.hibernate.cfg.EJB3NamingStrategy;
public class MyNamingStrategy extends EJB3NamingStrategy {
private static final long serialVersionUID = -5713413771290957530L;
@Override
public String collectionTableName(String ownerEntity, String ownerEntityTable, String associatedEntity, String associatedEntityTable, String propertyName) {
String name = null;
if ( "localized".equals( propertyName ) ) {
// NOTE: The problem is that ownerEntity is not the fully qualified class name since 4.2.15 anymore
name = ownerEntity.replaceAll( "\\.", "_" ).toUpperCase() + "_LOCALIZED";
}
if ( name == null ) {
name = super.collectionTableName( ownerEntity, ownerEntityTable, associatedEntity, associatedEntityTable, propertyName );
}
return name;
}
}

View File

@ -0,0 +1,43 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.hibernate.test.namingstrategy.regression;
import static org.junit.Assert.assertEquals;
import org.hibernate.cfg.Configuration;
import org.hibernate.mapping.Map;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
public class NamingStrategyTest extends BaseCoreFunctionalTestCase {
@Override
public void configure(Configuration cfg) {
super.configure( cfg );
cfg.setNamingStrategy( new MyNamingStrategy() );
}
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { Workflow.class };
}
@Test
@TestForIssue(jiraKey = "HHH-9327")
public void testNamingStrategyRegression() throws Exception {
String expectedName = Workflow.class.getName().replaceAll( "\\.", "_" ).toUpperCase();
expectedName += "_LOCALIZED";
PersistentClass classMapping = configuration().getClassMapping( Workflow.class.getName() );
Property property = classMapping.getProperty( "localized" );
Map map = (Map) property.getValue();
assertEquals( expectedName, map.getCollectionTable().getName() );
}
}

View File

@ -0,0 +1,95 @@
/*
* 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.test.namingstrategy.regression;
import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.CollectionTable;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.MapKeyColumn;
@Entity
public class Workflow implements Serializable {
private static final long serialVersionUID = 7504955999101475681L;
private Long id;
private Locale defaultLanguage;
private Set<Locale> supportedLocales = new HashSet<Locale>();
private Map<Locale, LocalizedEntity> localized = new HashMap<Locale, LocalizedEntity>();
public Workflow() {
}
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Basic(optional = false)
public Locale getDefaultLanguage() {
return defaultLanguage;
}
public void setDefaultLanguage(Locale defaultLanguage) {
this.defaultLanguage = defaultLanguage;
}
@ElementCollection
@CollectionTable(joinColumns = { @JoinColumn(name = "ID", referencedColumnName = "ID", nullable = false, insertable = false, updatable = false) })
public Set<Locale> getSupportedLocales() {
return supportedLocales;
}
public void setSupportedLocales(Set<Locale> supportedLocales) {
this.supportedLocales = supportedLocales;
}
@ElementCollection
@CollectionTable(joinColumns = { @JoinColumn(name = "ID", referencedColumnName = "ID", nullable = false, insertable = false, updatable = false) })
@MapKeyColumn(name = "LANGUAGE_CODE", nullable = false, insertable = false, updatable = false)
public Map<Locale, LocalizedEntity> getLocalized() {
return localized;
}
public void setLocalized(Map<Locale, LocalizedEntity> localized) {
this.localized = localized;
}
}