Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to name ManyToMany table and ManyToOne column?

 
Ismael Upright
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,


When @ManyToMany annotation is used between 2 tables, table1 and table2, a new table is created with default name as table1_table2.

Is there a possibility of changing this default name to a custom one?


The same question comes with the @ManyToOne attribute inside the class. Is it possible to provide the custom name of such column?




Thanks in advance
 
Ismael Upright
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found solution...


Renaming the column with @ManyToOne annotation:

Use @JoinColumn(name="My_Custom_Column_Name") as a second annotation before attribute.



Renaming the column with @ManyToMany annotation:

Use @JoinTable(name="My_Custom_Table_Name") as a second annotation before attribute.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed, the @JoinColumn attribute allows you to specify a name. Of course, the annotation has to match your database, so be careful!

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic