HHH-7436 : Add FailureExpected test for unidirectional many-to-many
This commit is contained in:
parent
b95bcb31e6
commit
cc7cfb5c40
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0"?>
|
||||
<hibernate-mapping package="org.hibernate.metamodel.spi.binding"
|
||||
xmlns="http://www.hibernate.org/xsd/hibernate-mapping"
|
||||
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-mapping hibernate-mapping-4.0.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
|
||||
<class name="EntityWithUnidirectionalManyToManys">
|
||||
<id name="id">
|
||||
<generator class="increment"/>
|
||||
</id>
|
||||
<property name="name"/>
|
||||
<bag name="theBag">
|
||||
<key column="theBagOwner"/>
|
||||
<many-to-many class="SimpleEntity"/>
|
||||
</bag>
|
||||
<set name="theSet" lazy="false">
|
||||
<key column="theSetOwner" not-null="true"/>
|
||||
<many-to-many class="SimpleEntity"/>
|
||||
</set>
|
||||
<bag name="thePropertyRefBag" lazy="extra">
|
||||
<key column="ownerName" property-ref="name" not-null="true"/>
|
||||
<many-to-many class="SimpleEntity"/>
|
||||
</bag>
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* 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.metamodel.spi.binding;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
@Entity
|
||||
public class EntityWithUnidirectionalManyToManys {
|
||||
private Long id;
|
||||
private String name;
|
||||
private Collection<SimpleEntity> theBag = new ArrayList<SimpleEntity>();
|
||||
private Set<SimpleEntity> theSet = new HashSet<SimpleEntity>();
|
||||
private Collection<SimpleEntity> thePropertyRefBag = new ArrayList<SimpleEntity>();
|
||||
|
||||
public EntityWithUnidirectionalManyToManys() {
|
||||
}
|
||||
|
||||
public EntityWithUnidirectionalManyToManys(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Id
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@OneToMany
|
||||
public Collection<SimpleEntity> getTheBag() {
|
||||
return theBag;
|
||||
}
|
||||
|
||||
public void setTheBag(Collection<SimpleEntity> theBag) {
|
||||
this.theBag = theBag;
|
||||
}
|
||||
|
||||
@OneToMany
|
||||
public Set<SimpleEntity> getTheSet() {
|
||||
return theSet;
|
||||
}
|
||||
|
||||
public void setTheSet(Set<SimpleEntity> theSet) {
|
||||
this.theSet = theSet;
|
||||
}
|
||||
|
||||
@OneToMany
|
||||
public Collection<SimpleEntity> getThePropertyRefSet() {
|
||||
return thePropertyRefBag;
|
||||
}
|
||||
|
||||
public void setThePropertyRefSet(Set<SimpleEntity> thePropertyRefSet) {
|
||||
this.thePropertyRefBag = thePropertyRefSet;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* 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.metamodel.spi.binding;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.engine.FetchTiming;
|
||||
import org.hibernate.metamodel.MetadataSourceProcessingOrder;
|
||||
import org.hibernate.metamodel.MetadataSources;
|
||||
import org.hibernate.metamodel.internal.MetadataImpl;
|
||||
import org.hibernate.metamodel.spi.relational.Column;
|
||||
import org.hibernate.metamodel.spi.relational.ForeignKey;
|
||||
import org.hibernate.metamodel.spi.relational.Identifier;
|
||||
import org.hibernate.metamodel.spi.relational.Value;
|
||||
import org.hibernate.service.ServiceRegistryBuilder;
|
||||
import org.hibernate.service.internal.StandardServiceRegistryImpl;
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.type.BagType;
|
||||
import org.hibernate.type.CollectionType;
|
||||
import org.hibernate.type.SetType;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class UnidirectionalManyToManyBindingTests extends BaseUnitTestCase {
|
||||
private StandardServiceRegistryImpl serviceRegistry;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
serviceRegistry = (StandardServiceRegistryImpl) new ServiceRegistryBuilder().buildServiceRegistry();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
serviceRegistry.destroy();
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void testAnnotations() {
|
||||
// doTest( MetadataSourceProcessingOrder.ANNOTATIONS_FIRST );
|
||||
// }
|
||||
|
||||
@Test
|
||||
@FailureExpected( jiraKey = "HHH-7436" )
|
||||
public void testHbm() {
|
||||
doTest( MetadataSourceProcessingOrder.HBM_FIRST );
|
||||
}
|
||||
|
||||
private void doTest(MetadataSourceProcessingOrder processingOrder) {
|
||||
MetadataSources sources = new MetadataSources( serviceRegistry );
|
||||
sources.addResource( "org/hibernate/metamodel/spi/binding/EntityWithUnidirectionalManyToManys.hbm.xml" );
|
||||
sources.addResource( "org/hibernate/metamodel/spi/binding/SimpleEntity.hbm.xml" );
|
||||
MetadataImpl metadata = (MetadataImpl) sources.getMetadataBuilder().with( processingOrder ).buildMetadata();
|
||||
|
||||
final EntityBinding entityBinding = metadata.getEntityBinding( EntityWithUnidirectionalManyToManys.class.getName() );
|
||||
final EntityBinding simpleEntityBinding = metadata.getEntityBinding( SimpleEntity.class.getName() );
|
||||
assertNotNull( entityBinding );
|
||||
|
||||
assertEquals( Identifier.toIdentifier( "SimpleEntity" ), simpleEntityBinding.getPrimaryTable().getLogicalName() );
|
||||
assertEquals( 1, simpleEntityBinding.getPrimaryTable().getPrimaryKey().getColumnSpan() );
|
||||
Column simpleEntityIdColumn = simpleEntityBinding.getPrimaryTable().getPrimaryKey().getColumns().get( 0 );
|
||||
assertEquals( Identifier.toIdentifier("id") , simpleEntityIdColumn.getColumnName() );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue