java.lang.IllegalArgumentException:object不是声明类的实例吗?

时间:2016-12-20 00:29:26

标签: java xml eclipse hibernate mapping

这些是我的类,xml配置文件和我的控制台上打印的错误:

LigneFacture.java:

package model;

import java.io.Serializable;

public class LigneFacture implements Serializable {
    private int id;

    private int qte;

    // private Produit produit;
    private EnteteFacture enteteFacture;
    private Produit produit;

    public LigneFacture() {
        super();
    }

    public LigneFacture(int qte) {
        super();
        this.qte = qte;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public EnteteFacture getEnteteFacture() {
        return enteteFacture;
    }

    public void setEnteteFacture(EnteteFacture enteteFacture) {
        this.enteteFacture = enteteFacture;
    }

    public Produit getProduit() {
        return produit;
    }

    public void setProduit(Produit produit) {
        this.produit = produit;
    }

    public int getQte() {
        return qte;
    }

    public void setQte(int qte) {
        this.qte = qte;
    }

}

LigneFactureServlet.java:

package controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.LigneFactureDaoImpl;
import model.EnteteFacture;
import model.LigneFacture;
import model.Produit;
import services.EnteteFactureServiceImpl;
import services.LigneFactureServiceImpl;
import services.ProduitServiceImpl;

/**
 * Servlet implementation class LigneFactureServlet
 */
@WebServlet("/LigneFactureServlet")
public class LigneFactureServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public LigneFactureServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        RequestDispatcher disp = request.getRequestDispatcher("/View/AjouterLigneFacture.jsp");
        disp.forward(request, response);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        if ((request.getParameter("ajouterLigneFacture")) != null) {


            String stringquantite = request.getParameter("quantite");
            int qte = Integer.parseInt(stringquantite);
            String[] entete = request.getParameterValues("enteteFacture");
            int codeEntete = Integer.parseInt(entete[0]);    
            String[] produit = request.getParameterValues("produit");
            int codeProd = Integer.parseInt(produit[0]); 

            EnteteFactureServiceImpl enteteFactureService = new EnteteFactureServiceImpl();
            // ClientServiceImpl produitService = new ClientServiceImpl();
            EnteteFacture enteteFacture = enteteFactureService.retourner(codeEntete);



            ProduitServiceImpl produitService = new ProduitServiceImpl();
            Produit product = produitService.retourner(codeProd);
            if (qte <= product.getQuantiteStock()) {

                product.setQuantiteStock((product.getQuantiteStock()) - qte);

                //ProduitServiceImpl produitService = new ProduitServiceImpl();
                produitService.modifier(product);                   
                LigneFacture ligneFacture = new LigneFacture();



                ligneFacture.setQte(qte);


                ligneFacture.setEnteteFacture(enteteFacture);
                Produit modifiedProduct = produitService.retourner(codeProd);
                ligneFacture.setProduit(modifiedProduct);    

                LigneFactureServiceImpl ligneFactureServiceImpl = new LigneFactureServiceImpl();
                ligneFactureServiceImpl.ajouter(ligneFacture);
                RequestDispatcher dispatcher = request.getRequestDispatcher("/View/AjouterLigneFacture.jsp");
                dispatcher.forward(request, response);

            } else {
                System.out.println("ERREUR !!!!!");

                RequestDispatcher dispat = request.getRequestDispatcher("/View/ErreurLigneFacture.jsp");
                dispat.forward(request, response);
            }
        }
    }
}

LigneFacture.hbm.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
 "-//Hibernate/Hibernate Mapping DTD//EN"
 "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="model.LigneFacture" table="LIGNE_FACTURE">

        <composite-id name="id" class="model.LigneFacture">

            <key-many-to-one name="Produit" entity-name="model.Produit"
                column="CODE_PRODUIT" />
            <key-many-to-one name="EnteteFacture" entity-name="model.EnteteFacture"
                column="ID_ENTETE_FACTURE" />
        </composite-id>


        <property name="qte" column="QUANTITE" />

    </class>
</hibernate-mapping>

EnteteFacture.hbm.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
 "-//Hibernate/Hibernate Mapping DTD//EN"
 "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> 
<hibernate-mapping>
   <class name="model.EnteteFacture" table="ENTETE_FACTURE">
      <meta attribute="class-description">
      </meta>
      <id name="id" column="ID_ENTETE_FACTURE">
         <generator class="native"/>
      </id>
      <property name="date" column="DATE" />
            <property name="total" column="TOTAL" />

      <many-to-one name="client" class="model.Client" fetch="select" update="true">
            <column name="ID_CLIENT" not-null="true" />
      </many-to-one>

            <set name="ligneFacture" table="LIGNE_FACTURE" inverse="true"
            fetch="select" cascade="all">
            <key>
                <column name="ID_ENTETE_FACTURE" not-null="true" />
            </key>
            <one-to-many class="model.LigneFacture" />
        </set>

   </class>
</hibernate-mapping>

Produit.hbm.xml:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
 "-//Hibernate/Hibernate Mapping DTD//EN"
 "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> 
<hibernate-mapping>
   <class name="model.Produit" table="PRODUIT">
      <meta attribute="class-description">
      </meta>
      <id name="codeProduit" column="CODE_PRODUIT">
         <generator class="native"/>
      </id>
      <property name="nom" column="NOM" />
      <property name="description" column="DESCRIPTION" />
      <property name="prix" column="PRIX" />
      <property name="quantiteStock" column="QUANTITE_STOCK" />
      <many-to-one name="categorie" class="model.Categorie" fetch="select" update="true">
            <column name="CODE_CATEGORIE" not-null="true" />
      </many-to-one>



            <set name="ligneFacture" table="LIGNE_FACTURE" inverse="true"
            fetch="select" cascade="all">
            <key>
                <column name="CODE_PRODUIT" not-null="true" />
            </key>
            <one-to-many class="model.LigneFacture" />
        </set>


   </class>
</hibernate-mapping>

这是我的控制台上的错误:

7088 [http-nio-8081-exec-2] ERROR org.hibernate.property.BasicPropertyAccessor - IllegalArgumentException in class: model.LigneFacture, getter method of property: Produit
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of model.LigneFacture.Produit
    at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:195)
    at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:87)
    at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:93)
    at org.hibernate.tuple.component.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:109)
    at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:376)
    at org.hibernate.type.ComponentType.getHashCode(ComponentType.java:207)
    at org.hibernate.engine.EntityKey.generateHashCode(EntityKey.java:126)
    at org.hibernate.engine.EntityKey.<init>(EntityKey.java:70)
    at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:184)
    at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:144)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
    at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
    at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
    at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:562)
    at org.hibernate.impl.SessionImpl.save(SessionImpl.java:550)
    at org.hibernate.impl.SessionImpl.save(SessionImpl.java:546)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:342)
    at com.sun.proxy.$Proxy4.save(Unknown Source)
    at dao.GenericDaoHibernateImpl.add(GenericDaoHibernateImpl.java:49)
    at dao.LigneFactureDaoImpl.ajouter(LigneFactureDaoImpl.java:12)
    at services.LigneFactureServiceImpl.ajouter(LigneFactureServiceImpl.java:25)
    at controller.LigneFactureServlet.doPost(LigneFactureServlet.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1100)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:687)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:169)
    ... 50 more

1 个答案:

答案 0 :(得分:0)

hbm中的类名应包含包名和类名,即整个类路径

只有这样,hibernate才能找到你的课程。