我使用Hibernate注释有如下关系,这就是我尝试过的:
public class Job{
...
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "jobs_resource_locations")
@ForeignKey(name = "job_inputs_fk")
@Index(name="job_inputs_fk")
private List<FileSystemLocation> inputs;
这样的事情很好地适用于ManyToOne,就像这样:
@ManyToOne
@JoinColumn(name = "service_call_id", referencedColumnName = "id")
@ForeignKey(name = "job_service_call_fk")
@Index(name = "job_service_call_fk")
private ServiceCall serviceCall;
我想确保外键在PostgreSQL上被索引,并且架构在MySQL上看起来相似,因此@ForeignKey和@Index具有相同的名称(MySQL总是创建一个与FK同名的索引)。
我无法在反面创建索引,因为FileSystemLocation不知道这种关系。因此,JoinTable。
前一个示例失败,因为Hibernate在Job中找不到要索引的列:
org.hibernate.MappingException: Unable to find logical column name from physical name null in table jobs
有没有人知道如何使用Hibernate在JoinTable外键上创建索引?
答案 0 :(得分:8)
这不是您希望收到的答案,但这是预期的行为。换句话说:这不受支持。有关更多详细信息,请参阅以下JIRA: