: mappedBy refers to an unknown property of the target entity

I am working on a simple practical application for using sleep mode. It has a simple display, for example, a manufacturer may have many mobile phones. But a mobile can only be made by one manufacturer. Here is what I think the code should be.

package mobileconsumers.entity.dto; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; @Entity @Table(name="ms_ref_mobile") public class MobileDTO { private Long id; private String model; private ManufacturerDTO manufacturerDTO; @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name="MOBILE_ID") public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getModel() { return model; } public void setModel(String model) { this.model = model; } @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="MANUFACTURER_ID") public ManufacturerDTO getManufacturer() { return manufacturerDTO; } public void setManufacturer(ManufacturerDTO manufacturer) { this.manufacturerDTO = manufacturer; } } 

this is the second dto

 package mobileconsumers.entity.dto; import java.util.HashSet; import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.Table; @Entity @Table(name="ms_ref_manufacturer") public class ManufacturerDTO { private Long id; private String name; private Set<MobileDTO> mobileDTOs = new HashSet<>(0); @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name="MANUFACTURER_ID") public Long getId() { return id; } public void setId(Long id) { this.id = id; } @Column(name="NAME") public String getName() { return name; } public void setName(String name) { this.name = name; } @OneToMany(fetch=FetchType.LAZY,mappedBy="manufacturerDTO") public Set<MobileDTO> getMobileDTOs() { return mobileDTOs; } public void setMobileDTOs(Set<MobileDTO> mobileDTOs) { this.mobileDTOs = mobileDTOs; } } 

When I try to start my server, this results in an error. org.hibernate.AnnotationException: mappedBy reference anunknown target entity property: mobileconsumers.entity.dto.MobileDTO.manufacturerDTO in mobileconsumers.entity.dto.ManufacturerDTO.mobileDTOs It seems that the picture suits me. there must be something really stupid that i'm missing. I just need fresh pairs of eyes to look at my code and find out what is going wrong.

+7
java spring hibernate jpa
source share
1 answer

Change the value of mappedBy so that it refers to the manufacturer property on the @ManyToOne side of the association:

 @OneToMany(fetch=FetchType.LAZY,mappedBy="manufacturer") public Set<MobileDTO> getMobileDTOs() { return mobileDTOs; } 
+7
source share

All Articles