• Post Reply Bookmark Topic Watch Topic
  • New Topic

adding jsf form fields in data base using hibernate  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good afternon, i have two fields fist Name and Last Name in ajout.xhtml when i press the button Save ,it is supposed to add first name and last name in table "Person" but it doesn't add data and it doesn't show nothing ,please i need your help.

//ajout.xhtml :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="http://www.w3.org/1999/xhtml"
<link href="style.css" rel="stylesheet" type="text.css"/>
<hutputText value="Last Name" />
<h:inputText value="#{PersonBean.per.lastName}" />
<hutputText value="First Name" />
<h:inputText value="#{PersonBean.per.firstName}" />
<h:commandButton value="Save" action="#{PersonBean.SavePerson}" />


import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import com.util.Person;
import java.util.List;
public class PersonBean {

PersonDao perdao;
Person per;
List<Person> perList;

public PersonBean() {
perdao = new PersonDao();

public Person getPer()
{return per;}
public void setPer(Person per)

public String SavePerson(){
return "rose";


import org.hibernate.Session;
import com.util.HibernateUtil;

public class PersonDao {

Session session = null;

public PersonDao(){
this.session = HibernateUtil.getSessionFactory().getCurrentSession();

public void savepersonne(com.util.Person per) {

org.hibernate.Transaction tx =session.beginTransaction();


//Person :

package com.util;
public class Person implements java.io.Serializable {

private static final long serialVersionUID = 1L;
private Integer id;
private String lastName;
private String firstName;

public Person() {

public Person(String lastName, String firstName) {
this.lastName = lastName;
this.firstName = firstName;

public Integer getId() {
return this.id;

public void setId(Integer id) {
this.id = id;

public String getLastName() {
return this.lastName;

public void setLastName(String lastName) {
this.lastName = lastName;

public String getFirstName() {
return this.firstName;

public void setFirstName(String firstName) {
this.firstName = firstName;


<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>

<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

<property name="hibernate.show_sql">true</property>

<mapping resource="com/util/Person.hbm.xml" />

Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!