0

I have this tables in SQL

-TABLE CATEGORY-
ID_CATEGORY, NAME

-TABLE CATEGORY_EVENTS-
ID_CATEGORY, ID_EVENT, COLUMNIWANT

-TABLE EVENTS-
ID_EVENT, NAME

Then I have my entitys in java like this

Category.java:

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID_CATEGORY")
private long idCategory;

@Column(name = "NAME")
private String name;

@IDONTKNOW
private int COLUMNIWANT

Event.java:

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID_EVENT")
private long idEvent;

@Column(name = "NAME")
private String name;

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "CATEGORY_EVENTS", 
         joinColumns = { @JoinColumn(name = "ID_EVENT") }, 
         inverseJoinColumns = { @JoinColumn(name = "ID_CATEGORY") })
private List<Category> categories = new ArrayList<Category>();

The COLUMNIWANT need to be inside each category in categories list inside events but it may not be in a normal category not associated to an event.

So my question is, how should I do the Hibernate mapping with the COLUMNIWANT property in categories.

Thank you in advance.

Jero Franzani
  • 473
  • 6
  • 19
  • you want COLUMNIWANT to be used but it should not save in Database while save/Update if so you can annotate it with @Transient – MyTwoCents Jul 05 '17 at 05:06
  • It's a classic structure: attributes in the link table. Maybe this helps https://stackoverflow.com/questions/5127129/mapping-many-to-many-association-table-with-extra-columns – RubioRic Jul 05 '17 at 06:30

0 Answers0