HHH-4283 fix the incorrect test case and add a proper exception when the user error occurs

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18421 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Emmanuel Bernard 2010-01-06 17:28:23 +00:00
parent 99e43e9d14
commit 658df91a5e
2 changed files with 11 additions and 3 deletions

View File

@ -35,6 +35,7 @@ import javax.persistence.AttributeOverrides;
import javax.persistence.ElementCollection; import javax.persistence.ElementCollection;
import javax.persistence.Embeddable; import javax.persistence.Embeddable;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable; import javax.persistence.JoinTable;
import javax.persistence.ManyToMany; import javax.persistence.ManyToMany;
import javax.persistence.MapKey; import javax.persistence.MapKey;
@ -464,6 +465,15 @@ public abstract class CollectionBinder {
//work on association //work on association
boolean isMappedBy = !BinderHelper.isDefault( mappedBy ); boolean isMappedBy = !BinderHelper.isDefault( mappedBy );
if (isMappedBy
&& (property.isAnnotationPresent( JoinColumn.class )
|| property.isAnnotationPresent( JoinTable.class ) ) ) {
String message = "Associations marked as mappedBy must not define database mappings like @JoinTable or @JoinColumn: ";
message += StringHelper.qualify( propertyHolder.getPath(), propertyName );
throw new AnnotationException( message );
}
collection.setInverse( isMappedBy ); collection.setInverse( isMappedBy );
//many to many may need some second pass informations //many to many may need some second pass informations
@ -487,7 +497,7 @@ public abstract class CollectionBinder {
|| property.isAnnotationPresent( CollectionOfElements.class ) //legacy hibernate || property.isAnnotationPresent( CollectionOfElements.class ) //legacy hibernate
|| property.isAnnotationPresent( ElementCollection.class ) //JPA 2 || property.isAnnotationPresent( ElementCollection.class ) //JPA 2
) { ) {
// do it right away, otherwise @ManyToon on composite element call addSecondPass // do it right away, otherwise @ManyToOne on composite element call addSecondPass
// and raise a ConcurrentModificationException // and raise a ConcurrentModificationException
//sp.doSecondPass( CollectionHelper.EMPTY_MAP ); //sp.doSecondPass( CollectionHelper.EMPTY_MAP );
mappings.addSecondPass( sp, !isMappedBy ); mappings.addSecondPass( sp, !isMappedBy );

View File

@ -42,7 +42,6 @@ public class AddressBook {
@MapKey @MapKey
@OneToMany(mappedBy = "book", cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE}) @OneToMany(mappedBy = "book", cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE})
@JoinTable(name="AddRegEntry")
public Map<AddressEntryPk, AddressEntry> getEntries() { public Map<AddressEntryPk, AddressEntry> getEntries() {
return entries; return entries;
} }
@ -63,7 +62,6 @@ public class AddressBook {
@MapKey(name = "directory") @MapKey(name = "directory")
@OneToMany(mappedBy = "book") @OneToMany(mappedBy = "book")
@JoinTable(name="Dir_Entry")
public Map<AlphabeticalDirectory, AddressEntry> getDirectoryEntries() { public Map<AlphabeticalDirectory, AddressEntry> getDirectoryEntries() {
return directoryEntries; return directoryEntries;
} }