0

I use spring data jpa and i try to do a many to many unidirectional relation.

@Entity
public class Appartment {
   ...
   @ManyToMany
   private List<AppartmentFeatureOption> featureOption;
} 

@Entity
public class AppartmentFeatureOption {
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long appartmentFeatureOptionId;

  private String name;

  private BigDecimal value;
}

My database is created at run time, but i get this error

org.hibernate.DuplicateMappingException: Same physical table name [appartment_feature_option] references several logical table names: [AppartmentFeatureOption], [Appartment_AppartmentFeatureOption]

Any idea?

Edit with this code that work

@ManyToMany
@JoinTable(name="appartment_feautre_option_appartment", joinColumns=@JoinColumn(name="appartment_id"), inverseJoinColumns=@JoinColumn(name="appartment_feautre_option_id"))  
private List<AppartmentFeatureOption> featureOption;
robert trudel
  • 5,283
  • 17
  • 72
  • 124

1 Answers1

-1

Is this is actually your real code, maybe the issue is that you are using a ManyToMany relationship between Appartment and AppartmentFeatureOption whereas there is no link to Appartment in the AppartmentFeatureOption.

From my understanding for one Appartment you want to have several AppartmentFeatureOption, which is a OneToMany relationship.

afraisse
  • 3,362
  • 1
  • 12
  • 13
  • An one to many will not work, same option can be used in different appartment. – robert trudel Sep 01 '15 at 13:10
  • Yes but... One to many means that for one apartment you can have several options – afraisse Sep 01 '15 at 13:12
  • If there is a business value in being able to retrieve _apartments_ from _options_, then you need a ManyToMany relationship, if not it is a OneToMany... Still, I'm glad you found the answer to your question in the end ;) – afraisse Sep 01 '15 at 13:38
  • I don't understand why you worry about duplication. In both cases the relationship will result in a join table holding only IDs from the _Apartment_ & _ApartmentFeatureOptions_. The join table ID will be the pair _(AppartmentId,AppartmentFeatureId)_ – afraisse Sep 02 '15 at 05:07
  • with many to many and one to many, the created table is not really the same. – robert trudel Sep 03 '15 at 00:06