6

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, but 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.

2
  • Have a look here: stackoverflow.com/questions/4400169 Commented Sep 2, 2011 at 9:12
  • Eventualy I gave up on making some indexes on Hibernate 4.2 and previous. Hibernate 4.3 will support JPA 2.1 which supports indexes right inside @JoinTable. Commented Oct 5, 2013 at 12:03

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.