Below are the two entities with the relationships in a unidirectional way:
CustomerService.java
@Entity
@Table(name = "customer_service")
@Multitenant
@TenantDiscriminatorColumn(name = "tenant_id", discriminatorType = DiscriminatorType.INTEGER, contextProperty = PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT)
public class CustomerService implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_customer_service")
private Long id;
@Column(name = "tenant_id", insertable = false, updatable = false)
private Long tenantId;
@Column(name = "date_service")
@DateTimeFormat(pattern = "dd/MM/yyyy")
@Temporal(TemporalType.DATE)
private Date date;
@Column(name = "average_budget")
private BigDecimal averageBudget;
@Column(name = "service_situation")
private boolean situation;
@OneToMany
@JoinColumn(name="fk_customerService")
private Set<ServiceItem> serviceItem;
//Getter and Setter...
}
Destination.java
@Entity
@Table(name="destination")
@Multitenant
@TenantDiscriminatorColumn(name="tenant_id", discriminatorType=DiscriminatorType.INTEGER, contextProperty=PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT)
public class Destination implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id_destination")
private Long idDestination;
@Column(name="tenant_id", insertable=false, updatable=false)
private Long tenantId;
@OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER)
@JoinColumn(name="fk_destination")
@Valid
private Set<Image> images;
@OneToMany
@JoinColumn(name="fk_destination")
private Set<ServiceItem> serviceItem;
//Geter and Setter...
}
ServiItem.java
@Entity
@Table(name = "service_item")
@Multitenant
@TenantDiscriminatorColumn(name = "tenant_id", discriminatorType = DiscriminatorType.INTEGER, contextProperty = PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT)
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@id")
public class ServiceItem implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_service_item")
private Long id;
private Destination destination;
private CustomerService customerService;
//Getter and Setter
}
Well, the generation of the tables in the DB is done by eclipselink, but it is creating (besides the fk_customerService and fk_destination columns), plus two columns like FK! Here is an image to illustrate the problem:
How can I fix this generation?