Füllen Dropdownlist mit Datenbank-Wert in Struts 2, Hibernate

Ich versuche, füllen Sie eine Dropdown-Liste mit Werten aus einer Tabelle . Die Seite verwendet strust2 und hibernate zu access-Datenbank.

Kann ich die Ansicht der Registrierungs-Seite (enthält die drop-down -, die gefüllt mit Datenbank-Werte)
Aber kein Wert angezeigt in der drop-down-Liste.

index.jsp

  <s:url id="url" action="registerAction">

  </s:url>
  <s:a href="%{url}">Register</s:a>

registrieren.jsp

 <s:form action="registerAction">
    <s:select label="Select Date of Month" name="months" headerKey="0" headerValue="--Select--"
                      list="allMonths" listKey="id" listValue="name"/>
    <s:submit value="Register"/>

 </s:form>

struts.xml

<action name="registerAction" class="action.RegisterAction" method="populateSelect">
       <result name="none">register.jsp</result>
</action>

Monat Modell

@Entity
@Table(name="tbl_mnth")
public class Month {
    @Id
    @GeneratedValue
    @Column(name="mnth_id")
    private int id;
    @Column(name="mnth_name")
    private String name;

    public Month(){}

    public Month(String name) {
        this.name=name;
    }

    public String getName() {
        return name;
    }
}

DAO

public class UserDao {

 List<Month> allMonths = new ArrayList<Month>();
public List<Month> getAllMonths() {
        return allMonths;
    }

    public void setAllMonths(List<Month> allMonths) {
        this.allMonths = allMonths;
    }

    public Session getSession() {
        return HibernateUtil.getSession();
    }

    public void closeSession() {
        HibernateUtil.closeSession();
    }

    public UserDao() {
    }

    public List<Month> getMonths() {
        Session session = getSession();
        Transaction t = session.beginTransaction();
        allMonths = (List<Month>) session.createQuery("FROM Month").list();
        System.out.println("In constructor " + allMonths);
        t.commit();
        closeSession();
        return allMonths;
    }
}

Action-Klasse

public class RegisterAction extends ActionSupport {
List<Month> allMonths = new ArrayList<Month>();
String months;
UserDao udao = new UserDao();

public List<Month> getAllMonths() {
        return allMonths;
    }

    public void setAllMonths(List<Month> allMonths) {
        this.allMonths = allMonths;
    }
    public String getMonths() {
        return months;
    }

    public void setMonths(String months) {
        this.months = months;
    }
    public String populateSelect() {
        allMonths = udao.getMonths();
        System.out.println("In constructor " + allMonths);
        return "none";
    }
    public RegisterAction() {}
}

Datenbank-Tabelle tbl_mnth mit Feldern mnth_id, mnth_name.

Was ich Vermutungen ist, dass der action-Klasse wird nicht instanziiert. ich weiß nicht, wie oder warum es nicht instanziiert werden..

In server-log-es zeigt

org.hibernate.hql.ast.QuerySyntaxException: Month is not mapped [from Month]

InformationsquelleAutor Eva Mariam | 2013-09-21

Schreibe einen Kommentar