我正在尝试将对象映射到以下连接表,
表名: booking_pax
3列: booking_id , pax_id , pax_no_in_tour
主键: booking_id , pax_id
外键: booking_id 参考预订表, pax_id 参考表
CREATE TABLE `booking_pax` (
`booking_id` int(8) unsigned NOT NULL,
`pax_id` int(8) unsigned NOT NULL,
`pax_numb_in_tour` int(2) unsigned DEFAULT NULL,
PRIMARY KEY (`booking_id`,`pax_id`),
KEY `booking_booking_pax` (`booking_id`),
KEY `pax_booking_pax` (`pax_id`),
CONSTRAINT `booking_booking_pax` FOREIGN KEY (`booking_id`) REFERENCES `booking` (`booking_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `pax_booking_pax` FOREIGN KEY (`pax_id`) REFERENCES `pax` (`pax_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
)
我有两个实体: pax 和预订。由于关系是ManyToMany,并且有一个额外的列需要添加到此连接表中 现在我遇到了使用Hibernate进行映射的问题。
建模:
@Entity
public class Booking {
......
@ManyToMany
@JoinTable(
name="booking_pax",
joinColumns={@JoinColumn(name="booking_id")},
inverseJoinColumns={@JoinColumn(name="pax_id")}
)
//@ElementCollection
//@Column(name="pax_numb_in_tour")
public Map<Pax, Integer> getPaxs() {
return paxs;
}
......
}
错误消息:
org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.....model.Booking.paxs[java.lang.Integer]
我已经尝试了很多方法来映射集合,但仍然无法正常工作。 我正在使用的IDE是带有JaveEE 5的MyEclipse 8.6。我尝试升级到JavaEE 6但是失败了。
感谢。
答案 0 :(得分:0)
未经测试的:
@ElementCollection
@CollectionTable(
name="booking_pax",
joinColumns={@JoinColumn(name="booking_id")}
)
@Column(name="pax_numb_in_tour")
@MapKeyJoinColumn(name="pax_id")
public Map<Pax, Integer> getPaxs() {
return paxs;
}