@Entity
public class Entry
{
@Id @GeneratedValue
private long identifier;
@ElementCollection
@Column(nullable = false)
private Map<String, String> titles;
@ElementCollection
@Column(nullable = false)
@Lob
private Map<String, String> contents;
// Getters and setters, other fields and methods
}
지도 "내용"의 값이 커질 수 있기 때문에이 @Lob 주석을 사용합니다. map "contents"의 키가 데이터베이스에 매핑되는 방법에 대해서는 신경 쓰지 않습니다. @Lob 주석을지도의 값에만 적용해야한다고 지정하는 방법을 찾지 못했습니다.
Entry.titles가 문제없이 데이터베이스에 매핑되는 동안 Entry.contents는 매핑되지 않습니다. 데이터베이스 테이블이 생성되지 않고 MySQL/Hibernate가 다음과 같이 불평합니다 :
Unsuccessful: create table myblog.Entry_contents (Entry_identifier bigint not null, contents longtext not null, contents_KEY longtext, primary key (Entry_identifier, contents_KEY)) type=InnoDB
BLOB/TEXT column 'contents_KEY' used in key specification without a key length
어떤 아이디어라도 감사하겠습니다!
버그가 만든 : http://opensource.atlassian.com/projects/hibernate/ 찾아보기/JPA-11 –