Hey y'all!
I'm currently evaluating Castor and want to realize a 1:n relationship
between companies (e.g., A owns B and C, and B owns D--companies are
organized in trees). I tried different table organizations and mappings, but
Castor seems to have trouble with the fact that a Company instance directly
manages Company instances.
My question is: How would your DB tables look and how your mapping XML file?
Thanks,
Paul
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public
class Company
{
private Integer id;
private String name;
private char[] country;
private Set employees = new HashSet();
private Set companies = new HashSet();
public
Company()
{
}
public
Integer
getId()
{
return id;
}
public
void
setId( Integer id )
{
this.id = id;
}
public
String
getName()
{
return name;
}
public
void
setName( String name )
{
this.name = name;
}
public
char[]
getCountry()
{
if ( country == null ) {
return null;
}
char[] countryCode = new char[ 2 ];
countryCode[ 0 ] = country[ 0 ];
countryCode[ 1 ] = country[ 1 ];
return countryCode;
}
public
void
setCountry( char[] countryCode )
{
if ( countryCode == null ) {
country = null;
return;
}
country = new char[ 2 ];
country[ 0 ] = countryCode[ 0 ];
country[ 1 ] = countryCode[ 1 ];
}
public
Set
getEmployees()
{
return employees;
}
public
void
addEmployee( Employee employee )
{
employees.add( employee );
}
public
void
setEmployees( Set employees )
{
if ( employees != null ) {
this.employees.addAll( employees );
}
}
public
Set
getCompanies()
{
return companies;
}
public
void
addCompany( Company company )
{
companies.add( company );
}
public
void
setCompanies( Set companies )
{
if ( companies != null ) {
this.companies.addAll( companies );
}
}
public
String
toString()
{
Iterator eIterator = employees.iterator();
Iterator cIterator = companies.iterator();
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append( "Company (" );
stringBuffer.append( id ).append( ", " ).append( "name"
).append( ", " ).append( country != null ? country[ 0 ] : 'n' ).append(
country != null ? country[ 1 ] : 'l' ).append( ", " );
stringBuffer.append( "{" );
if ( eIterator.hasNext() ) {
stringBuffer.append( eIterator.next() );
}
while ( eIterator.hasNext() ) {
stringBuffer.append( ", " ).append( eIterator.next()
);
}
stringBuffer.append( "}" );
stringBuffer.append( ", " );
stringBuffer.append( "{" );
if ( cIterator.hasNext() ) {
stringBuffer.append( cIterator.next() );
}
while ( cIterator.hasNext() ) {
stringBuffer.append( ", " ).append( cIterator.next()
);
}
stringBuffer.append( "}" );
stringBuffer.append( ")" );
return stringBuffer.toString();
}
}
public
//abstract
class Employee
{
private int id;
private String name;
public
Employee()
{
}
public
int
getId()
{
return id;
}
public
void
setId( int id )
{
this.id = id;
}
public
String
getName()
{
return name;
}
public
void
setName( String name )
{
this.name = name;
}
public
String
toString()
{
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append( "Employee (" );
stringBuffer.append( id ).append( ", " ).append( name );
stringBuffer.append( ")" );
return stringBuffer.toString();
}
}
__________________________________
Paul E. Sevin�, Dipl. El.-Ing. ETH
Software Engineer
[EMAIL PROTECTED]
+41 1 456 3243
ELCA
Steinstrasse 21
Postfach
8036 Z�rich
Switzerland
Company.java
Employee.java