최대 절전 모드 5.2로 단일 테이블 상속을 구현하려고합니다.SingleTable로 Hibernate 상속
@Entity
@DiscriminatorValue("COMPOSER")
class Composer extends PropertyOwner {
}
사람 클래스 :
public class Person {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
long id;
String title;
}
속성 CIA 요원
@Entity
@DiscriminatorValue("AUTHOR")
class Author extends PropertyOwner {
}
작곡가 클래스는 PropertyOwner 확장 : 기본 클래스
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="type", discriminatorType= DiscriminatorType.STRING)
@DiscriminatorValue("HAKSAHIBI")
@DiscriminatorOptions(force=true)
public class PropertyOwner implements implements Serializable{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
long id;
@ManyToOne
Property property;
@ManyToOne
Person person;
}
저자 클래스는 PropertyOwner를 확장 SS
public class Property{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
long id;
String title;
@OneToMany
Set<Composer> composers = new HashSet<Composer>();
@OneToMany
Set<Author> authors = new HashSet<Author>();
}
나는 다음과 같은 테이블 구조를 기대하고
:
CREATE TABLE `Property` (
`id` bigint(20) NOT NULL,
`title` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `Person` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`title` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `PropertyOwner` (
`type` varchar(31) NOT NULL,
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`property_id` bigint(20) DEFAULT NULL,
`person_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK77apjkkl14xwe45rs1ocgtt4u` (`property_id`),
KEY `FKqagfofgupovfly26enivfhm3j` (`person_id`),
CONSTRAINT `FK77apjkkl14xwe45rs1ocgtt4u` FOREIGN KEY (`property_id`) REFERENCES `property` (`id`),
CONSTRAINT `FKqagfofgupovfly26enivfhm3j` FOREIGN KEY (`person_id`) REFERENCES `person` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
을하지만 불행하게도 그것이 내가 뭘 잘못 문
CREATE TABLE `property_propertyOwner` (
`Property_id` bigint(20) NOT NULL,
`author_id` bigint(20) NOT NULL,
`composer_id` bigint(20) NOT NULL,
UNIQUE KEY `UK_rv9fxc06rcydqp6dqpqbmrkie` (`author_id`),
UNIQUE KEY `UK_fm4v55i021l5smuees0vs3qmy` (`composer_id`),
KEY `FKt3yqcltkd0et8bj08ge0sgrqb` (`Property_id`),
CONSTRAINT `FK1pj2606cjxrb70ps89v7609hg` FOREIGN KEY (`author_id`) REFERENCES `PropertyOwner` (`id`),
CONSTRAINT `FKfdh3r95jffvd07u3xn21824r7` FOREIGN KEY (`composer_id`) REFERENCES `PropertyOwner` (`id`),
CONSTRAINT `FKt3yqcltkd0et8bj08ge0sgrqb` FOREIGN KEY (`Property_id`) REFERENCES `Property` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
다음과 같이 저자와 작곡가 클래스 다른 테이블을 생성? 나는 property_PropertyOwner 테이블이 생성되어서는 안되고 Author, Composer 클래스 정보가 propertyOwner 테이블에 있어야한다고 기대하고 있습니다.
참고 : Enumarated 주석을 사용해 봤지만 이번에는 Setauthor 필드를 정의 할 수없는 속성 클래스에서 Set을 정의하고 해당 개체에 enum 정보를 추가해야합니다. 미리 감사드립니다.
매핑에'mappedBy'가 누락 된 것 같습니다. –