2012-07-03 2 views
0

Я использую jsf2 hibernate 4.1.4 и spring3 в своем проекте. но в моем defaut.xhtml я могу только вставлять данные в oracle. но я не вижу данные на своей странице. добавить нового клиента. но код таблицы данных в моем jsf не может работать. моя ошибка:jsf 2 and oracle

value="#{CustomerMB.getCustomerList()}":org.hibernate.hql.internal.ast.QuerySyntaxException: CUSTOMER is not mapped [from CUSTOMER] 

default.xhtml

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:h="http://java.sun.com/jsf/html" 
     xmlns:f="http://java.sun.com/jsf/core" 
     > 
    <h:head> 
     <h:outputStylesheet library="css" name="table-style.css" /> 
    </h:head> 

    <h:body> 



     <h:dataTable value="#{CustomerMB.getCustomerList()}" var="c" 
       styleClass="order-table" 
       headerClass="order-table-header" 
       rowClasses="order-table-odd-row,order-table-even-row" 
      > 

      <h:column> 
       <f:facet name="header"> 
        Customer ID 
       </f:facet> 
        #{c.customerId} 
      </h:column> 

      <h:column> 
       <f:facet name="header"> 
        Name 
       </f:facet> 
        #{c.name} 
      </h:column> 

      <h:column> 
       <f:facet name="header"> 
        Address 
       </f:facet> 
        #{c.address} 
      </h:column> 

      <h:column> 
       <f:facet name="header"> 
        Created Date 
       </f:facet> 
        #{c.createdDate} 
      </h:column> 

     </h:dataTable> 

     <h2>Add New Customer</h2> 
     <h:form> 

      <h:panelGrid columns="3"> 
       Customer ID : 
       <h:inputText id="customerId" value="#{CustomerMB.customerId}" 
        size="20" required="true" 
        label="customerId" > 
       </h:inputText> 

       <h:message for="customerId" style="color:red" /> 
       Name : 
       <h:inputText id="name" value="#{CustomerMB.name}" 
        size="20" required="true" 
        label="Name" > 
       </h:inputText> 

       <h:message for="name" style="color:red" /> 

       Address : 
       <h:inputTextarea id="address" value="#{CustomerMB.address}" 
        cols="30" rows="10" required="true" 
        label="Address" > 
       </h:inputTextarea> 

       <h:message for="address" style="color:red" /> 

created Date : 
       <h:inputTextarea id="createdDate" value="#{CustomerMB.createdDate}" 
        size="20" required="true" 
        label="createdDate" > 
       </h:inputTextarea> 

      </h:panelGrid> 

      <h:commandButton value="Submit" action="#{CustomerMB.addCustomer()}" /> 

     </h:form> 

    </h:body> 

</html> 

Customermanagedbean.java

@ManagedBean(name="CustomerMB") 
@RequestScoped 
public class Customermanagedbean implements Serializable{ 
@ManagedProperty(value="#{CustomerBoImpl}") 
ICustomerBo customerBoImpl; 
List<Customer> CustomerList; 
public int customerId; 
public String name; 
public String address; 
public String createdDate; 



public ICustomerBo getCustomerBoImpl() { 
    return customerBoImpl; 
} 
public void setCustomerBoImpl(ICustomerBo customerBoImpl) { 
    this.customerBoImpl = customerBoImpl; 
} 

public List<Customer> getCustomerList() { 
    CustomerList=new ArrayList<Customer>(); 
    CustomerList.addAll(getCustomerBoImpl().findAllCustomer()); 

    return CustomerList; 
} 



public void setCustomerList(List<Customer> customerList) { 
    CustomerList = customerList; 
} 
public int getCustomerId() { 
    return customerId; 
} 
public void setCustomerId(int customerId) { 
    this.customerId = customerId; 
} 
public String getName() { 
    return name; 
} 
public void setName(String name) { 
    this.name = name; 
} 
public String getAddress() { 
    return address; 
} 
public void setAddress(String address) { 
    this.address = address; 
} 
public String getCreatedDate() { 
    return createdDate; 
} 
public void setCreatedDate(String createdDate) { 
    this.createdDate = createdDate; 
} 
//add a new customer data into database 
public String addCustomer(){ 

    Customer cust = new Customer(); 
    cust.setCustomerId(getCustomerId()); 
    cust.setName(getName()); 
    cust.setAddress(getAddress()); 
cust.setCreatedDate(getCreatedDate()); 

    getCustomerBoImpl().addCustomer(cust); 


    clearForm(); 

    return ""; 
} 

//clear form values 
private void clearForm(){ 
     setName(""); 
    setAddress(""); 
    setCreatedDate(""); 
} 


} 

CustomerBoImpl.java

@Transactional(readOnly = true) 
public class CustomerBoImpl implements ICustomerBo{ 

    ICustomerDao customerDaoImpl; 



    public ICustomerDao getCustomerDaoImpl() { 
     return customerDaoImpl; 
    } 

    public void setCustomerDaoImpl(ICustomerDao customerDaoImpl) { 
     this.customerDaoImpl = customerDaoImpl; 
    } 

@Transactional(readOnly = false) 
@Override 
    public void addCustomer(Customer customer){ 

     getCustomerDaoImpl().addCustomer(customer); 

    } 

@Transactional(readOnly = false) 
@Override 
    public void updateCustomer(Customer customer){ 
     getCustomerDaoImpl().updateCustomer(customer); 
    } 

@Transactional(readOnly = false) 
@Override 
    public void deleteCustomer(Customer customer){ 
     getCustomerDaoImpl().deleteCustomer(customer); 
    } 

@Override 
    public List<Customer> findAllCustomer(){ 

     return getCustomerDaoImpl().findAllCustomer(); 
    } 
} 

что не так? enter image description here

customer.java

@Entity 
@Table(name="CUSTOMER") 

public class Customer{ 

    public int customerId; 
    public String name; 
    public String address; 
    public String createdDate; 

    @Id 
    @Column(name="CUSTOMER_ID", unique = true, nullable = false) 
    public int getCustomerId() { 
     return customerId; 
    } 
    public void setCustomerId(int customerId) { 
     this.customerId = customerId; 
    } 
    @Column(name="NAME") 
    public String getName() { 
     return name; 
    } 
    public void setName(String name) { 
     this.name = name; 
    } 
    @Column(name="ADDRESS") 
    public String getAddress() { 
     return address; 
    } 
    public void setAddress(String address) { 
     this.address = address; 
    } 
    @Column(name="CREATED_DATE") 
    public String getCreatedDate() { 
     return createdDate; 
    } 
    public void setCreatedDate(String createdDate) { 
     this.createdDate = createdDate; 
    } 



} 

CustomerDaoImpl.java

public class CustomerDaoImpl implements ICustomerDao{ 
    private SessionFactory sessionFactory; 
    public SessionFactory getSessionFactory() { 
     return sessionFactory;} 
    public void setSessionFactory(SessionFactory sessionFactory) { 
     this.sessionFactory = sessionFactory; 
    } 

    public void addCustomer(Customer customer){ 
     sessionFactory.openSession(); 
     getSessionFactory().getCurrentSession().save(customer); 

    } 

    public void updateCustomer(Customer customer){ 
     sessionFactory.openSession(); 
     getSessionFactory().getCurrentSession().update(customer); 
    } 

    public void deleteCustomer(Customer customer){ 
     sessionFactory.openSession(); 
     getSessionFactory().getCurrentSession().delete(customer); 
    } 


    public List<Customer> findAllCustomer(){ 
     sessionFactory.openSession(); 

     List list = getSessionFactory().getCurrentSession 

().createQuery("from CUSTOMER").list(); 
     return list; 

    } 
} 
+0

Проверили ли вы список из getCustomerList () на самом деле заполнены данными? – Tomer

+0

@ ftom2, no. как мне это сделать? – samira

+0

Просто введите оператор журнала из списка. – Tomer

ответ

0

проблема была в моей CustomerDaoImpl.java. В HQL, вы должны использовать имя класса Java и имя свойства преобразованного @Entity вместо фактического имени таблицы и столбца, поэтому HQL должно быть:

List list = getSessionFactory().getCurrentSession().createQuery("from Customer").list(); 
     return list; 
+0

Вы можете принять ваши собственные ответы, если он работает для вас :) – Ravi

+0

@ Рави, я могу принять свой ответ через 2 дня. – samira