Unidirectional one-to-many + static mapping joinTable + self-referenced entity

J

juancarsanval

Guest
Can anybody help me to get the following tables

Code:
PERSON(ID, BIRTH_COUNTRY_ID, FATHER_ID, MATE_ID, MOTHER_ID, NAME)
PERSON_FAVORITE_COLORS(PERSON_ID, COLOR_ID)
PERSON_NATIONALITIES(PERSON_ID, NATIONALITY_ID)
PERSON_OFFSPRING(PERSON_ID, SCION_ID)
PERSON_PREFERRED_COUNTRIES(PERSON_ID, COUNTRY_ID, IDX)
COLOR(ID, CODE, NAME)
COUNTRY(ID, CODE, NAME)

for the following Groovy domain entities?:

/grails-app/domain/Person.groovy:
Code:
class Person {
		
		Country birthCountry
		Persona father
		List favoriteColors
		Persona mate
		Persona mother
		String name
		Collection nationalities
		Collection offspring
		List preferredCountries	

		static constraints = {
			birthCountry (nullable: true)
			father (nullable: true)
			favoriteColors  (nullable: true, size: 0..5)
			mate (nullable: true, unique: true)
			mother (nullable: true)
			name (nullable: false, blank: false, size: 1..50)				
			nationalities (nullable: true, size: 0..3)
			offspring (nullable: true)				
			preferredCountries (nullable: true, size: 0..4)		
		}	
		
		static hasMany = [
			favoriteColors: Color,
			nationalities: Country,
			offspring: Person,
			preferredCountries: Country
		]
		
	}

/grails-app/domain/Country.groovy:
Code:
class Country {
				
		String code;
		String name;	
		
		static constraints = {
			code (nullable: false, unique: true, size: 3..3, pattern: "[A-Z]{3}")
			name (nullable: false, blank: false, unique: true, size: 1..75)
		}	
		
	}

/grails-app/domain/Color.groovy:
Code:
class Color {	
		
		Integer code;
		String name;		
		
		static constraints = {
			code (nullable: false, unique: true)
			name (nullable: false, blank: false, unique: true, size: 1..50)			
		}
		
	}


I have tried with "static mapping joinTable" and "static mappedBy", but
I have get several GORM/Hibernate errors:
org.codehaus.groovy.grails.exceptions.GrailsDomainException,
org.hibernate.MappingException.

I'm desperate!
I'll settle for any solution that does not involve Hibernate XML configuration
and/or JPA annotation. It would valid for me bidirectionality in the relations.

Thanks in advance.
 
Top