I use hibernate-3.2, hibernate-annotations-3.3.1.CR1.
There are two classes.
First(BigBoard) can be independent of second(BoardList):
Code:
package board;
import java.util.Map;
import java.util.TreeMap;
import javax.persistence.*;
@Embeddable
@Entity
@Table(name = "BIGBOARDS")
public class BigBoard {
@Id @GeneratedValue
@Column(name = "BIGBOARD_ID")
private Long id;
@Column(name = "CITY")
private String city;
@Column(name = "LOCATION")
private String location;
@org.hibernate.annotations.CollectionOfElements
@JoinTable(
name = "BIGBOARD_STATUS",
joinColumns = @JoinColumn(name = "BIGBOARD_ID")
)
@Column(name = "STATUS", nullable = false)
@org.hibernate.annotations.OrderBy(
clause = "MONTH"
)
@org.hibernate.annotations.MapKey(
columns = @Column(name = "MONTH")
)
private Map<String, String> status = new TreeMap<String, String>();
//Constructor, accessor methods, equals()/hashCode()
}
This class has been mapped perfect:Code:
alter table BIGBOARD_STATUS
drop constraint FKF7B8706B92263A02;
drop table BIGBOARDS if exists;
drop table BIGBOARD_STATUS if exists;
create table BIGBOARDS (
BIGBOARD_ID bigint generated by default as identity (start with 1),
CITY varchar(255),
LOCATION varchar(255),
primary key (BIGBOARD_ID)
);
create table BIGBOARD_STATUS (
BIGBOARD_ID bigint not null,
STATUS varchar(255) not null,
MONTH varchar(255),
primary key (BIGBOARD_ID, MONTH)
);
alter table BIGBOARD_STATUS
add constraint FKF7B8706B92263A02
foreign key (BIGBOARD_ID)
references BIGBOARDS;
The second class:Here I have tried a lot of different ways to tell Hibernate how it would save it. Code:
package board;
import java.util.*;
import javax.persistence.*;
@Entity
@Table(name = "BOARDLISTS")
public class BoardList {
@Id @GeneratedValue
@Column(name = "BOARDLIST_ID")
private Long id;
@Column(name = "DATE")
private Date date = new Date();
//@What's here?
private SortedSet<BigBoard> bigBoardList = new TreeSet<BigBoard>();
//Constructor, accessor methods, equals()/hashCode()
}
I've not got correct mapped BoardList.
I'd love get any advice. Thanks in advance.