Scaffolding code

  • 연관을 맺기 위해 필요한 필드와 메소드.

1:다 관계

  • 다수를 가질 경우, Hibernate requires interfaces for collection-typed attributes
  • 양방향일 경우, 해당 타입의 속성이 필요함.
  • 연결하기: 두 가지 행위가 필요함.
  • Hibernate doesn't manage persistent associations. If you
    want to manipulate an association, you must write exactly the same code
    you would write without Hibernate.
  • Convenient Method 도입하기:
1:다 관계
public void addChildCategory(Category childCategory) {
if (childCategory == null)
throw new IllegalArgumentException("Null child category!");
if (childCategory.getParentCategory() != null)
childCategory.getParentCategory().getChildCategories().remove(childCategory);
childCategory.setParentCategory(this);
childCategories.add(childCategory);
}
    • reduces the lines of code
    • enforces the cardinality of the association

다:다 관계

  • both sides are implemented with collection-valued attributes.
  • Convenient Method
다:다 관계
public void addCategory(Category category) {
if (category == null)
throw new IllegalArgumentException("Null category");
category.getItems().add(this);
categories.add(category);
}
  • You can also add logic to your accessor methods.

참조 : Java Persistence With Hibernate