Объект не будет отображаться из базы данных MySQL - PullRequest
0 голосов
/ 03 апреля 2019

Я работаю над проектом (настольное приложение, использующее JavaEE, jboss и maven) и пытаюсь отобразить данные из моей базы данных.Он показывает ClassNotFoundException, я использовал system.out.println ("привет"), чтобы увидеть, где происходит сбой кода, и я пришел к выводу, что он находится в "student = proxy.getStudents ();"линия.Может кто-нибудь, пожалуйста, объясните мне, в чем проблема.Я даже попытался изменить List () на ArrayList (), потому что я прочитал здесь, что List () не может быть напрямую создан, так как код не будет работать.У меня также есть предупреждение [Resource Path Location Type Classpath запись C: / Program Files / Java / jdk1.8.0_181 / lib / javafx-mx.jar помечена для публикации / экспорта, но не экспортируется в путь к классам проекта.Видимость пути к классам в Eclipse и во время выполнения будет отличаться.student_placement_platform-ejb P / student_placement_platform-ejb Сообщение о проверке зависимости пути к классам] и после прочтения на некоторых форумах я пришел к выводу, что мой проект не читает файл persistence.xml, поэтому я помещаю его в META-INF под src / java /ресурсы.

это моя main.java:

package tn.esprit.student_placement_platform_client.tests;

import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import tn.esprit.student_placement_platform.entities.User;
import tn.esprit.student_placement_platform.iservices.FormServicesRemote;

public class FormTest {
    public static void main(String[] args) throws InterruptedException, NamingException {

        String jndiName = "student_placement_platform-ear/student_placement_platform-ejb/FormServices!tn.esprit.student_placement_platform.iservices.FormServicesRemote";



Description Resource    Path    Location    Type
Classpath entry C:/Program Files/Java/jdk1.8.0_181/lib/javafx-mx.jar is marked for publish/export but is not exported on the project classpath. Classpath visibility within Eclipse and at runtime will differ. student_placement_platform-ejb      P/student_placement_platform-ejb    Classpath Dependency Validator Message
Description Resource    Path    Location    Type
Console configuration "student_placement_platform-ejb" does not exist. Hibernate specific validation and content assist will be limited.    student_placement_platform-ejb      line 0  JPA Problem
Description Resource    Path    Location    Type
No connection specified for project. No database-specific validation will be performed. student_placement_platform-ejb          JPA Problem


        Context context = new InitialContext();
        FormServicesRemote proxy = (FormServicesRemote) context.lookup(jndiName);
        List<User> students = null;
        students = proxy.getStudents();
        //System.out.println("here");
        proxy.displayAll(students);

это моя консоль после запуска main.java:

avr. 03, 2019 7:03:38 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.0.Beta2
avr. 03, 2019 7:03:38 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.3.0.Beta2
avr. 03, 2019 7:03:38 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.5.Beta1
avr. 03, 2019 7:03:38 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage
INFO: EJBCLIENT000017: Received server version 2 and marshalling strategies [river]
avr. 03, 2019 7:03:38 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@370736d9, receiver=Remoting connection EJB receiver [connection=Remoting connection <a0f2de5>,channel=jboss.ejb,nodename=desktop-nosg5hn]} on channel Channel ID b1f98621 (outbound) of Remoting connection 339d465a to /127.0.0.1:18080
avr. 03, 2019 7:03:39 PM org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 2.0.1.Final
Exception in thread "main" javax.ejb.EJBException: java.lang.ClassNotFoundException: org.hibernate.PropertyAccessException
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:236)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:181)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:144)
    at com.sun.proxy.$Proxy2.getStudents(Unknown Source)
    at tn.esprit.student_placement_platform_client.tests.FormTest.main(FormTest.java:19)
Caused by: java.lang.ClassNotFoundException: org.hibernate.PropertyAccessException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.jboss.marshalling.AbstractClassResolver.loadClass(AbstractClassResolver.java:131)
    at org.jboss.marshalling.AbstractClassResolver.resolveClass(AbstractClassResolver.java:112)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:949)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1256)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
    at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1746)
    at org.jboss.marshalling.river.RiverObjectInputStream.defaultReadObject(RiverObjectInputStream.java:81)
    at java.lang.Throwable.readObject(Throwable.java:914)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.jboss.marshalling.reflect.SerializableClass.callReadObject(SerializableClass.java:307)
    at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1638)
    at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1607)
    at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1607)
    at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1607)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1286)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
    at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1746)
    at org.jboss.marshalling.river.RiverObjectInputStream.defaultReadObject(RiverObjectInputStream.java:81)
    at java.lang.Throwable.readObject(Throwable.java:914)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.jboss.marshalling.reflect.SerializableClass.callReadObject(SerializableClass.java:307)
    at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1638)
    at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1607)
    at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1607)
    at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1607)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1286)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
    at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)
    at org.jboss.ejb.client.remoting.InvocationExceptionResponseHandler$MethodInvocationExceptionResultProducer.getResult(InvocationExceptionResponseHandler.java:79)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:276)
    at org.jboss.ejb.client.EJBObjectInterceptor.handleInvocationResult(EJBObjectInterceptor.java:64)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:290)
    at org.jboss.ejb.client.EJBHomeInterceptor.handleInvocationResult(EJBHomeInterceptor.java:88)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:290)
    at org.jboss.ejb.client.TransactionInterceptor.handleInvocationResult(TransactionInterceptor.java:46)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:290)
    at org.jboss.ejb.client.ReceiverInterceptor.handleInvocationResult(ReceiverInterceptor.java:129)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:265)
    at org.jboss.ejb.client.EJBClientInvocationContext.awaitResponse(EJBClientInvocationContext.java:453)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:20

``````````````````````````````````````````
this is my service class:

``````````````````````````````````
package tn.esprit.student_placement_platform.services;




import java.util.ArrayList;
import java.util.List;

import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import tn.esprit.student_placement_platform.entities.Category;
import tn.esprit.student_placement_platform.entities.Document;
import tn.esprit.student_placement_platform.entities.User;
import tn.esprit.student_placement_platform.iservices.FormServicesRemote;

@Stateless
@Remote
public class FormServices implements FormServicesRemote {

    @PersistenceContext(unitName = "student_placement_platform-ejb")
    EntityManager em;

    @Override
    public Document addForm(Document form) {
        em.persist(form);
        return form;

    }
    @Override
    public Category addCategory (Category cat) {
        em.persist(cat);
        return cat;

    }


    @Override
    public ArrayList<User> getStudents(){
        return (ArrayList<User>) em.createQuery("select u from User u", User.class).getResultList();
    }
    @Override
    public  void displayAll(List<User> l) {

        for(Object u : l){
            System.out.println(u);
        }

    }


}

````````````````````````````````````````````
and finally my interface:

``````````````````````````````````
package tn.esprit.student_placement_platform.iservices;



import java.util.ArrayList;
import java.util.List;

import javax.ejb.Remote;

import tn.esprit.student_placement_platform.entities.Category;
import tn.esprit.student_placement_platform.entities.Document;
import tn.esprit.student_placement_platform.entities.User;


@Remote
public interface FormServicesRemote {
    public Document addForm(Document form);
    public Category addCategory(Category cat);
    public ArrayList<User> getStudents();
    public  void displayAll(List<User> students);
}
````````````````````````````````
...