Create an index on a column of a CollectionTable using Hibernate
Suppose I have the following entity which models a subscriber and uses a CollectionTable
to model a list of subscriptions like so:
@Entity
@Table(name = "SUBSCRIBER")
public class Subscriber {
@ElementCollection
@CollectionTable(name = "PERSON_ORG_SUBSCRIPTIONS",
joinColumns = { @JoinColumn( name = "PERSON_ID", referencedColumnName = "PERSON_ID" ),
@JoinColumn( name = "ORG_ID", referencedColumnName = "ORG_ID" ) } )
@Column(name = "SUBSCRIPTION_NAME")
protected Set<String> _subscriptionNames;
}
So this creates a table with columns for PERSON_ID
, ORG_ID
and SUBSCRIPTION_NAME
.
I'm trying to create a database index on the SUBSCRIPTION_NAME
column. But if I put the following annotation on _subscriptionNames
:
@org.hibernate.annotations.Index( name="subscription_idx", columnNames={"SUBSCRIPTION_NAMES"} )
I get an exception:
org.hibernate.MappingException: Unable to find logical column name from physical name null in table SUBSCRIBER
I also tried using the org.hibernate.annotations.Table
annotation on the Subscriber
entity, b开发者_开发问答ut there does not seem to be a way to have it reference the PERSON_ORG_SUBSCRIPTIONS
table.
I'm using Hibernate 3.5.3 and PostgreSQL 9.0.
Is the column with name "SUBSCRIPTION_NAME" present in the table SUBSCRIBER?
Are you planning to create index on table from the code? You should propably use hibernate.hbm2ddl.auto=create
精彩评论