|
|
|
|
|
|
Consider:
{code:borderStyle=solid} @Entity public class Boy { @EmbeddedId protected PK id;
@CollectionOfElements protected Collection<Toy> toys;
protected Boy() { }
public Boy(String firstName, String lastName) { id = new PK(firstName, lastName); }
public String getFirstName() { return id.getFirstName(); }
public String getLastName() { return id.getLastName(); }
public Collection<Toy> getToys() { return toys != null ? toys : (toys = new LinkedList<Toy>()); }
@Override public int hashCode() { return id.hashCode(); }
@Override public boolean equals(Object rhs) { return rhs == this || (rhs instanceof Boy && id.equals(((Boy) rhs).id)); }
@Override public String toString() { return id.toString(); }
@Embeddable public static class PK implements Serializable { @Basic protected String firstName;
@Basic protected String lastName;
protected PK() { }
public PK(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; }
public String getFirstName() { return firstName; }
public String getLastName() { return lastName; }
@Override public int hashCode() { return lastName.hashCode(); }
@Override public boolean equals(Object rhs) { return this == rhs || (rhs instanceof PK && firstName.equals(((PK) rhs).firstName) && lastName.equals(((PK) rhs).lastName)); }
@Override public String toString() { return String.format("%s %s", firstName, lastName); } }
@Embeddable public static class Toy implements Serializable { @Basic protected String name;
protected Toy() { }
public Toy(String name) { this.name = name; }
public String getName() { return name; }
@Override public int hashCode() { return name.hashCode(); }
@Override public boolean equals(Object rhs) { return this == rhs || (rhs instanceof Toy && name.equals(((Toy) rhs).name)); }
@Override public String toString() { return name; } } } {code}
{code:borderStyle=solid} public String foreignKeyColumnName(String propertyName, String propertyEntityName, String propertyTableName, String referencedColumnName) { String header = propertyName != null ? addUnderscores( propertyName ) : propertyTableName; if ( header == null ) throw new AssertionFailure( "NamingStrategy not properly filled" ); return columnName( header + "_" + referencedColumnName ); } {code} because referencedColumnName comes in as id.firstName.
DefaultComponentSafeNamingStrategy could:
1. override columnName() and call addUnderscores(columnName) or 2. call addUnderscores(referencedColumnName)
Thanks, Michael
|
|
|
|
|
|