I hava to entities with One to Many relationship, how to use Set as a foreign key. Country.java
package hello.world.entity;
import javax.persistence.*;
@Entity
@Table(name="country")
public class Country {
@Id
@Column(name="code", length=3, nullable=false)
private String code;
@Column(name="name", length=256, nullable=false)
private String name;
}
CountryLanguage.java
@Entity
@Table(name="country_language")
public class CountryLanguage {
@Id
private int id; // column Id desnt exist on table
@ManyToOne(cascade=CascadeType.ALL, targetEntity=Country.class)
@JoinColumn(name="code")
private Set<Country> countryCode = new HashSet<>();
@Column(name="language", length=256, nullable=false)
private String language;
How can use CountryLanguageRepository to getData by Country code
I have like this right now
@Repository
public interface CountryLanguageRepository extends JpaRepository<CountryLanguage, String> {
Set<CountryLanguage> findOneByCountryCode(String code);
}
Table CountryLanguage doesnt have an ID, but hibernate ask to add it. I have an Exception
column "id" contains null values
I have a key on table CountryLanguage (code,language)