I have 2 entities that are related through both a onetomany and a manytoone.
The owning entity uses a composite primairy key that consists of the foreign key from the owned entity.
If I remove the @Id in the owning entity (at getProfileType() in IProfileTypeImpl). Everyting seems to work (except for the fact that the key definition is incomplete of course), if I keep it there, I get an exception:
Code:
mappedBy reference an unknown target entity property: IProfileTypeImpl.profileType in ProfileTypeImpl.IProfileTypes
Alternative I could use an embedded entity to define my composite key, but will this solve my problem and will I still be able to implement the getters and setters from the interfaces properly?
The Owner Entity (IProfileTypeImpl):Code:
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import com.chicagometallic.productmaster.shared.IProfileType;
import com.chicagometallic.productmaster.shared.Language;
import com.chicagometallic.productmaster.shared.ProfileType;
@Entity
@Table(name = "i_profiletype")
public class IProfileTypeImpl extends PMDbEntryImpl implements IProfileType {
/**
*
*/
private static final long serialVersionUID = -4980796880003075949L;
private String profileTypeName;
private ProfileType profileType;
private Language language;
public IProfileTypeImpl() {
}
@Override
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@ManyToOne(targetEntity = LanguageImpl.class)
@JoinColumn(name = "languageid")
public Language getLanguage() {
return this.language;
}
@Override
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@ManyToOne(targetEntity = ProfileTypeImpl.class)
@JoinColumn(name = "profiletypeid")
public ProfileType getProfileType() {
return this.profileType;
}
@Override
@Basic
@Column(name = "profiletypename", length = 254)
public String getProfileTypeName() {
return this.profileTypeName;
}
@Override
public void setLanguage(final Language language) {
this.language = language;
}
@Override
public void setProfileType(final ProfileType profileType) {
this.profileType = profileType;
}
@Override
public void setProfileTypeName(final String profileTypeName) {
this.profileTypeName = profileTypeName;
}
}
The owned entity (ProfileTypeImpl) :Code:
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import com.chicagometallic.productmaster.shared.IProfileType;
import com.chicagometallic.productmaster.shared.ProfileType;
import com.chicagometallic.productmaster.shared.SystemRelation;
@Entity
@Table(name = "profiletype")
public class ProfileTypeImpl extends PMDbEntryImpl implements ProfileType {
/**
*
*/
private static final long serialVersionUID = -1781738964008203370L;
private Boolean defaultProfileType;
private Integer profileTypeId;
private List<SystemRelation> systemRelations;
private List<IProfileType> iProfileTypes;
public ProfileTypeImpl() {
}
@Override
@Basic
@Column(name = "defaultprofiletype")
public Boolean isDefaultProfileType() {
return this.defaultProfileType;
}
@Override
@Basic
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "profiletypeid", scale = 8, columnDefinition = "mediumint")
public Integer getProfileTypeId() {
return this.profileTypeId;
}
@Override
@OneToMany(targetEntity = SystemRelationImpl.class)
@JoinColumn(name = "profileType")
public List<SystemRelation> getSystemRelations() {
return this.systemRelations;
}
@Override
public void setDefaultProfileType(final Boolean defaultProfileType) {
this.defaultProfileType = defaultProfileType;
}
@Override
public void setProfileTypeId(final Integer profileTypeId) {
this.profileTypeId = profileTypeId;
}
@Override
public void setSystemRelations(final List<SystemRelation> systemRelations) {
this.systemRelations = systemRelations;
}
@Override
@OneToMany(targetEntity = IProfileTypeImpl.class, mappedBy = "profileType")
public List<IProfileType> getIProfileTypes() {
return this.iProfileTypes;
}
@Override
public void setIProfileTypes(final List<IProfileType> iProfileTypes) {
this.iProfileTypes = iProfileTypes;
}
}