I have a Customers
table that has AddressEmbedded
in it.
I also have a hardcoded table Countries
where I already have a region for every country, country is the primary key.
I want to join AddressEmbedded
and Countries
so I used the ManyToOne
and put CountryEntity
in AddressEmbedded
.
But I'm getting an error that mapstruct can't generate setCountry
.
So the question is, how do I make AddressEmbedded.setCountry(string country)
?
It's supposed to do a call to the db to get the corresponding region for that country, but it seems wrong to add a db call in a setter.
Here are the entity definitions:
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Data
@Embeddable
public class AddressEmbedded {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "country")
private CountryEntity country;
}
@Data
@Entity
@Table(name = "Countries")
public class CountryEntity {
@Id
@Column(name = "country")
private String country;
@Column(name = "region")
private String region;
}
@Data
@Entity
@Table(name = "Customers")
public class CustomerEntity {
@Embedded
private AddressEmbedded address;
}