Its working for me. In my case I have entities appUser and screen. However I have implemented it slightly differently using unique constraint on entity instead of inside column annotation as follows:
Entity AppUser:
@Entity
@Table(
name="app_user",
schema="public",
uniqueConstraints={
@UniqueConstraint(columnNames={"username"}),
@UniqueConstraint(columnNames={"email_id"}),
@UniqueConstraint(columnNames={"screen_name"}),
}
)
public class AppUser {
Integer appUserId;
String firstName;
String lastName;
String username;
String password;
String emailId;
String phoneNumber;
City city;
Industry industry;
String companyName;
Set<Authority> authorities = new HashSet<>(0);
Boolean active;
String emailConfirmationToken;
Screen screen;
public AppUser() {
super();
}
public AppUser(Integer appUserId, String firstName, String lastName, String username, String password,
String emailId, String phoneNumber, City city, Industry industry, String companyName,
Set<Authority> authorities, Boolean active, String emailConfirmationToken,
Screen screen) {
super();
this.appUserId = appUserId;
this.firstName = firstName;
this.lastName = lastName;
this.username = username;
this.password = password;
this.emailId = emailId;
this.phoneNumber = phoneNumber;
this.city = city;
this.industry = industry;
this.companyName = companyName;
this.authorities = authorities;
this.active = active;
this.emailConfirmationToken = emailConfirmationToken;
this.screen = screen;
}
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="app_user_id")
public Integer getAppUserId() {
return appUserId;
}
public void setAppUserId(Integer appUserId) {
this.appUserId = appUserId;
}
@Column(name="first_name")
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@Column(name="last_name")
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Column(name="username")
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@Column(name="password")
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Column(name="email_id")
public String getEmailId() {
return emailId;
}
public void setEmailId(String emailId) {
this.emailId = emailId;
}
@Column(name="phone_number")
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
@ManyToOne
@JoinColumn(name="city_id")
public City getCity() {
return city;
}
public void setCity(City city) {
this.city = city;
}
@ManyToOne
@JoinColumn(name="industry_id")
public Industry getIndustry() {
return industry;
}
public void setIndustry(Industry industry) {
this.industry = industry;
}
@Column(name="company_name")
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
@ManyToMany
@JoinTable(
name="app_user_authority",
joinColumns={@JoinColumn(name="app_user_id",nullable=false,updatable=false)},
inverseJoinColumns={@JoinColumn(name="authority_id",nullable=false,updatable=false)}
)
public Set<Authority> getAuthorities() {
return authorities;
}
public void setAuthorities(Set<Authority> authorities) {
this.authorities = authorities;
}
@Column(name="active")
public Boolean getActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
@Column(name="email_confirmation_token")
public String getEmailConfirmationToken() {
return emailConfirmationToken;
}
public void setEmailConfirmationToken(String emailConfirmationToken) {
this.emailConfirmationToken = emailConfirmationToken;
}
@OneToOne
@JoinColumn(name="screen_name",referencedColumnName="screen_name")
public Screen getScreen() {
return screen;
}
public void setScreen(Screen screen) {
this.screen = screen;
}
}
Entity Screen:
@Entity
@Table(name="screen",schema="public",
uniqueConstraints={@UniqueConstraint(columnNames="screen_name")})
@JsonIgnoreProperties(ignoreUnknown=true)
public class Screen extends OEntity<Screen> implements Serializable{
Integer screenId;
String screenName;
String address;
ScreenType screenType;
ScreenSize screenSize;
BigDecimal latitude;
BigDecimal longitude;
@SecureUpdate({"ROLE_ADMIN"})
Boolean active;
public Screen() {
super();
}
public Screen(Integer screenId, String screenName, String address, ScreenType screenType, ScreenSize screenSize,
BigDecimal latitude, BigDecimal longitude, Boolean active) {
super();
this.screenId = screenId;
this.screenName = screenName;
this.address = address;
this.screenType = screenType;
this.screenSize = screenSize;
this.latitude = latitude;
this.longitude = longitude;
this.active = active;
}
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="screen_id")
public Integer getScreenId() {
return screenId;
}
public void setScreenId(Integer screenId) {
this.screenId = screenId;
}
@Column(name="screen_name")
public String getScreenName() {
return screenName;
}
public void setScreenName(String screenName) {
this.screenName = screenName;
}
@Column(name="address")
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@ManyToOne
@JoinColumn(name="screen_type_id")
public ScreenType getScreenType() {
return screenType;
}
public void setScreenType(ScreenType screenType) {
this.screenType = screenType;
}
@ManyToOne
@JoinColumn(name="screen_size_id")
public ScreenSize getScreenSize() {
return screenSize;
}
public void setScreenSize(ScreenSize screenSize) {
this.screenSize = screenSize;
}
@Column(name="latitude",precision=12,scale=9)
public BigDecimal getLatitude() {
return latitude;
}
public void setLatitude(BigDecimal latitude) {
this.latitude = latitude;
}
@Column(name="longitude",precision=12,scale=9)
public BigDecimal getLongitude() {
return longitude;
}
public void setLongitude(BigDecimal longitude) {
this.longitude = longitude;
}
@Column(name="active")
public Boolean getActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
}
Also I had to implement Serializable on Screen.