[hibernate-issues] [Hibernate-JIRA] Created: (ANN-646) DefaultComponentSafeNamingStrategy leaves '.' in column names on collection of elements table when container has compound PK

Michael Newcomb (JIRA) noreply at atlassian.com
Fri Aug 3 11:12:11 EDT 2007


DefaultComponentSafeNamingStrategy leaves '.' in column names on collection of elements table when container has compound PK
----------------------------------------------------------------------------------------------------------------------------

                 Key: ANN-646
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-646
             Project: Hibernate Annotations
          Issue Type: Bug
            Reporter: Michael Newcomb
            Priority: Trivial


Consider:

@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;
    }
  }
}

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 );
}

because referencedColumnName comes in as id.firstName.

DefaultComponentSafeNamingStrategy could:

1. override columnName() and call addUnderscores(columnName) or
2. call addUnderscores(referencedColumnName)

Thanks,
Michael

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list