Problems in JPA, @OneToOne and mappedBy

2

I have three classes, Person, Client and Address, being Client of Person's Child and Address by adding Person.

Follow Person:

@Entity
public abstract class Pessoa implements Serializable {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long id;
private String nome;
private String cpf;
private String email;
private String pw;
private String numeroEnd;
private String complementoEnd;

@OneToOne
public Endereco endereco;

Next Address:

@Entity
public class Endereco implements Serializable {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)    
private long   id;
private String cep;
private String logradouro;
private String bairro;
private String cidade;
private String uf;

@OneToOne(mappedBy = "post", cascade = CascadeType.ALL, orphanRemoval = true)
private Pessoa pessoa;

The error I'm having is the following:

  Exception Description: An exception was thrown while searching for persistent archives with ClassLoader: WebappClassLoader (delegate = true; repositories = WEB-INF / classes /) Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.EntityManagerSetupException Exception Description: Predeployment of PersistenceUnit [LojaGamesPU] failed. Internal Exception: Exception [EclipseLink-7154] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.ValidationException Exception Description: The attribute [person] in entity class [class br.com.lojagames .model.Endereco] has a mappedBy value of [post] which does not exist in its owning entity class [class br.com.lojagames.model.Personal]. If the owning entity class is a @MappedSuperclass, this is invalid, and your attribute should reference the correct subclass.

I am a layman in JPA but would like to do to gain experience, though I believe that I did the relationship between classes in the JPA in the wrong way, could you point out the error?     

asked by anonymous 05.07.2017 / 19:53

1 answer

1
  The attribute [person] in entity class [class br.com.lojagames.model.Endereco] has a mappedBy value of [post] which does not exist in its owning entity class [class br.com.lojagames.model. Person]. If the owning entity class is a @MappedSuperclass, this is invalid, and your attribute should reference the correct subclass.

The parameter mappedBy should be used when there is a bidirectional relationship, as is the case with you. But it should "map" the class that is calling it.

@OneToOne(mappedBy = "endereco", cascade = CascadeType.ALL, orphanRemoval = true)
    
05.07.2017 / 20:12