0

In a OneToOne relationship,I Can't persist The fields of Adresse but I get no error for School fields it's give this error:

javax.el.PropertyNotFoundException: /inscription/school-inscription.xhtml @29,91 value="#{createBn.school.adresse.country}": Target Unreachable, 'null' returned null

here is the view:

<h:inputText id="name" value="#{createBn.school.name}" pt:placeholder="ex: Dalton" />

<h:inputText value="#{createBn.school.creationDate}" pt:placeholder="31-12-2000" />

<h:selectOneMenu value="#{createBn.school.adresse.country}" styleClass="form-control">
    <f:selectItems value="#{countriesList.countries}" />
</h:selectOneMenu>.....

so createBn:

@Named
@SessionScoped
public class CreateBn implements Serializable{
private static final long serialVersionUID = 1L;

private School school;

@EJB
private SchoolPr schoolPr;

public CreateBn(){
    user = new User();
    school = new School();
}

public void createSchool(){
    schoolPr.createSchool(school);
}

and here are the School Entity and the Adress Entity:

@Entity
@Table(schema = "school", name = "school")
public class School implements Serializable {
....
private String name;

@OneToOne @JoinColumn(name = "adressId")
private Adresse adresse;
//getters +setters

Adress:

@Entity
@Table(schema = "school", name = "adress")
class Adresse implements java.io.Serializable {
..
private String country;
//getters +setters

Ps: I already see similar cases here but nothing helps + I delete most of the code posted here like ID fields and so, all getters and setters are implemented.

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
user3923327
  • 137
  • 1
  • 4
  • 11

1 Answers1

0

value="#{createBn.school.adresse.country}": Target Unreachable, 'null' returned null

This means that one of the following values is null:

  • #{createBn}
  • #{createBn.school}
  • #{createBn.school.adresse}

The createBn looks okay at first sight (otherwise you'd have other problems as well). The school looks okay as you explicitly created it with new School(). However, I'm not seeing that for adresse anywhere. Fix it accordingly.

school.setAdresse(new Adresse());
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452