HHH-6361 - Fixed ManyToManyAssociationClassCompositeIdTest broken by
CollectionType changes
This commit is contained in:
parent
f9049a1fd2
commit
c22e7fd214
|
@ -1,45 +1,58 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008-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.manytomanyassociationclass.compositeid;
|
||||
|
||||
import org.hibernate.test.manytomanyassociationclass.AbstractManyToManyAssociationClassTest;
|
||||
import org.hibernate.test.manytomanyassociationclass.Membership;
|
||||
|
||||
/**
|
||||
* Tests on many-to-many association using an association class with a composite ID containing
|
||||
* the IDs from the associated entities.
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class ManyToManyAssociationClassCompositeIdTest extends AbstractManyToManyAssociationClassTest {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] { "manytomanyassociationclass/compositeid/Mappings.hbm.xml" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public Membership createMembership( String name ) {
|
||||
return new MembershipWithCompositeId( name );
|
||||
}
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008-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.manytomanyassociationclass.compositeid;
|
||||
|
||||
import org.hibernate.test.manytomanyassociationclass.AbstractManyToManyAssociationClassTest;
|
||||
import org.hibernate.test.manytomanyassociationclass.Group;
|
||||
import org.hibernate.test.manytomanyassociationclass.Membership;
|
||||
import org.hibernate.test.manytomanyassociationclass.User;
|
||||
|
||||
/**
|
||||
* Tests on many-to-many association using an association class with a composite ID containing
|
||||
* the IDs from the associated entities.
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class ManyToManyAssociationClassCompositeIdTest extends AbstractManyToManyAssociationClassTest {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] { "manytomanyassociationclass/compositeid/Mappings.hbm.xml" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public Membership createMembership( String name ) {
|
||||
return new MembershipWithCompositeId( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMembership(User u, Group g, Membership ug) {
|
||||
if ( u == null || g == null ) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
u.getMemberships().remove( ug );
|
||||
g.getMemberships().remove( ug );
|
||||
ug.setId(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -64,19 +64,34 @@ public class MembershipWithCompositeId extends Membership {
|
|||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if ( o != null && o instanceof Id ) {
|
||||
Id that = ( Id ) o;
|
||||
return this.userId.equals( that.userId ) &&
|
||||
this.groupId.equals( that.groupId );
|
||||
}
|
||||
else {
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Id other = (Id) obj;
|
||||
if (userId == null) {
|
||||
if (other.userId != null)
|
||||
return false;
|
||||
} else if (!userId.equals(other.userId))
|
||||
return false;
|
||||
if (groupId == null) {
|
||||
if (other.groupId != null)
|
||||
return false;
|
||||
} else if (!groupId.equals(other.groupId))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return userId.hashCode() + groupId.hashCode();
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((userId == null) ? 0 : userId.hashCode());
|
||||
result = prime * result
|
||||
+ ((groupId == null) ? 0 : groupId.hashCode());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,11 +104,17 @@ public class MembershipWithCompositeId extends Membership {
|
|||
}
|
||||
|
||||
public void setGroup(Group group) {
|
||||
if (getId() == null) {
|
||||
setId(new Id());
|
||||
}
|
||||
( (Id) getId() ).setGroupId( ( group == null ? null : group.getId() ) );
|
||||
super.setGroup( group );
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
if (getId() == null) {
|
||||
setId(new Id());
|
||||
}
|
||||
( (Id) getId() ).setUserId( user == null ? null : user.getId() );
|
||||
super.setUser( user );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue