-1

Thi is my JPA code I am using jpa,jsf,primefaces,and maven. Also I am using mysql. Actually if there is no database I can access beans data into my jsf page but these are not working now. I am sharing codes.

public class UsersJPA {
EntityManager em;
EntityManagerFactory emf;
private List<Users> users = new ArrayList<>();

public UsersJPA() 
{
    emf = Persistence.createEntityManagerFactory("com.kanbagisi_kanbagisi_war_1.0PU");
    em = emf.createEntityManager();
    em.getTransaction().begin();
}
public List<Users> getUsers()
{
    try
    {
        users =  em.createNamedQuery("Users.findAll",Users.class).getResultList();
        return users;
    }
    catch (Exception e)
    {
        return users;
    }
}}

This is my ManagedBeans code. Actually ı want yo using CDI but I am a beginner. Also I am using netbeans IDE.

@ManagedBean
@SessionScoped
public class testBean implements Serializable {
    private List<Users> userss = new ArrayList<>();
    private UsersJPA ujpa = new UsersJPA();

public testBean() {
}
public List<Users> getUserss() {
    return userss;
}

public void setUserss(List<Users> userss) {
    this.userss = userss;
}

public UsersJPA getUjpa() {
    return ujpa;
}

public void setUjpa(UsersJPA ujpa) {
    this.ujpa = ujpa;
}
 public List<Users> getir()
{
    userss = ujpa.getUsers();
    return userss;
}
}

Jsf Codes(Primefaces)

<h:head>
    <title>Facelet Title</title>
</h:head>
<h:body>
        <h:form>
            <p:dataTable value="#{testBean.getir()}" var="veri" >
                <p:column headerText="SURNAME">
                    <h:outputText value="#{veri.surname}"/>
                </p:column>
            </p:dataTable>

        </h:form>


</h:body>
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
mete eroğlu
  • 95
  • 2
  • 10
  • Off-topic: read https://stackoverflow.com/questions/2090033/why-jsf-calls-getters-multiple-times and where is your 'beans' class? – Kukeltje Mar 27 '18 at 14:22

1 Answers1

-1

Also this is my entity class. But ı think there is no error here because it is a automated.

@Entity
@Table(name = "users")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Users.findAll", query = "SELECT u FROM Users u")})
public class Users implements Serializable {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "user_id")
private Integer userId;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 255)
@Column(name = "user_name")
private String userName;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 255)
@Column(name = "user_password")
private String userPassword;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 255)
@Column(name = "name")
private String name;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 255)
@Column(name = "surname")
private String surname;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 255)
@Column(name = "mail_adress")
private String mailAdress;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 255)
@Column(name = "blood")
private String blood;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 255)
@Column(name = "tel_number")
private String telNumber;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 255)
@Column(name = "adress")
private String adress;
@Basic(optional = false)
@NotNull
@Column(name = "active_deactive")
private int activeDeactive;

public Users() {
}

public Users(Integer userId) {
    this.userId = userId;
}

public Users(Integer userId, String userName, String userPassword, String name, String surname, String mailAdress, String blood, String telNumber, String adress, int activeDeactive) {
    this.userId = userId;
    this.userName = userName;
    this.userPassword = userPassword;
    this.name = name;
    this.surname = surname;
    this.mailAdress = mailAdress;
    this.blood = blood;
    this.telNumber = telNumber;
    this.adress = adress;
    this.activeDeactive = activeDeactive;
}

public Integer getUserId() {
    return userId;
}

public void setUserId(Integer userId) {
    this.userId = userId;
}

public String getUserName() {
    return userName;
}

public void setUserName(String userName) {
    this.userName = userName;
}

public String getUserPassword() {
    return userPassword;
}

public void setUserPassword(String userPassword) {
    this.userPassword = userPassword;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getSurname() {
    return surname;
}

public void setSurname(String surname) {
    this.surname = surname;
}

public String getMailAdress() {
    return mailAdress;
}

public void setMailAdress(String mailAdress) {
    this.mailAdress = mailAdress;
}

public String getBlood() {
    return blood;
}

public void setBlood(String blood) {
    this.blood = blood;
}

public String getTelNumber() {
    return telNumber;
}

public void setTelNumber(String telNumber) {
    this.telNumber = telNumber;
}

public String getAdress() {
    return adress;
}

public void setAdress(String adress) {
    this.adress = adress;
}

public int getActiveDeactive() {
    return activeDeactive;
}

public void setActiveDeactive(int activeDeactive) {
    this.activeDeactive = activeDeactive;
}

@Override
public int hashCode() {
    int hash = 0;
    hash += (userId != null ? userId.hashCode() : 0);
    return hash;
}

@Override
public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof Users)) {
        return false;
    }
    Users other = (Users) object;
    if ((this.userId == null && other.userId != null) || (this.userId != null && !this.userId.equals(other.userId))) {
        return false;
    }
    return true;
}

@Override
public String toString() {
    return "com.entity.Users[ userId=" + userId + " ]";
}

}

mete eroğlu
  • 95
  • 2
  • 10