找不到JEE Web应用程序实体Wildfly [英] JEE Web Application Entity Not Found Wildfly

查看:115
本文介绍了找不到JEE Web应用程序实体Wildfly的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Wildfly 10. 我正在尝试将实体绑定到jsf页面,并使用jpa将其保存到我的数据库中.

I am using Wildfly 10. I am trying to bind an entity to a jsf page and save it with jpa to my db.

我得到一个 javax.servlet.ServletException:javax.ejb.EJBException:java.lang.IllegalArgumentException:未知实体:de.rupp.model.Contact $ Proxy $ _ $$ _ WeldClientProxy javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)

I am getting a javax.servlet.ServletException: javax.ejb.EJBException: java.lang.IllegalArgumentException: Unknown entity: de.rupp.model.Contact$Proxy$_$$_WeldClientProxy javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)

我在WEB-INF/classes/META-INF中的persistence.xml:

My persistence.xml in WEB-INF/classes/META-INF:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
   xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
        http://xmlns.jcp.org/xml/ns/persistence
        http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
   <persistence-unit name="contacts">
      <!-- If you are running in a production environment, add a managed 
         data source, this example data source is just for development and testing! -->
      <!-- The datasource is deployed as WEB-INF/jsftest-ds.xml, you
         can find it in the source at src/main/webapp/WEB-INF/jsftest-ds.xml -->
      <jta-data-source>java:/ContactsDS</jta-data-source>
      <class>de.rupp.model.Contact</class>
      <properties>
         <!-- Properties for Hibernate -->
         <property name="hibernate.hbm2ddl.auto" value="update" />
         <property name="hibernate.show_sql" value="false" />
      </properties>
   </persistence-unit>
</persistence>

我的实体

@Named
@RequestScoped
@Entity
@NamedQueries({
    @NamedQuery(name=Contact.FIND_ALL, query="SELECT c FROM Contact c"),
    @NamedQuery(name=Contact.DELETE_ALL, query="DELETE FROM Contact")
})
public class Contact implements Serializable{


    public final static String FIND_ALL = "Contacts.findAll";
    public final static String DELETE_ALL = "Contacts.deleteAll";

    /**
     * 
     */
    private static final long serialVersionUID = -7050382512059267701L;

    @Id
    @GeneratedValue
    private Long id;

    private String firstName;
    private String lastName;
    private String email;
    private String phone;
    private String message;


    //getter and setter omitted for brevity 

}

我的控制器

@Named
@RequestScoped
public class EingabeController implements Serializable {

    private Logger log = LoggerFactory.getLogger(EingabeController.class);

    @Inject
    private ContactsDAOBean contactsDAOBean;


    @Inject
    private Contact contact;


    public void save() {
        this.contactsDAOBean.save(this.contact);
        log.info(this.contact + " saved");
    }

}

我的持久层工作正常,为此我编写了Arquillian Test:

My persistence layer works I have written an Arquillian Test for this:

@RunWith(Arquillian.class)
public class ContactsDAOTest {


     @Deployment
        public static Archive<?> createTestArchive() {
            return ShrinkWrap.create(WebArchive.class, "test.war")
                    .addClasses(Contact.class, AbstractDAO.class, AbstractDAOBean.class, ContactsDAOBean.class)
                    .addAsResource("META-INF/persistence.xml")
                    .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");

        }




     @Inject
     private ContactsDAOBean contactsDAOBean;

     @Before
     public void init() {
         contactsDAOBean.deleteAll();
     }

     @Test
     public void save() {
         Contact contact = new Contact();
         contact.setEmail("h.rupp@dzbw.de");
         contact.setFirstName("Hans");
         contact.setLastName("Rupp");
         contact.setPhone("0711 8108 276232");
         contact.setMessage("Ich will hier raus");
         contactsDAOBean.save(contact);
         List<Contact> contacts = contactsDAOBean.findAll();
         assertEquals(1, contacts.size());
     }

}

任何想法都将不胜感激

-------------------编辑--------------------------- -----------

------------------- edit --------------------------------------

我重构了此页面: 最初,Contact实体已直接绑定到输入元素,例如

I have refactored this page: originally the Contact entity has been bound directly to the input elements like

<h:inputText value="#{contact.firstName}"  styleClass="form-control"/>

我已经更改了控制器,以便它产生要保存的实体.

I have changed the controller so that it produces the entity to be saved.

@Named
@RequestScoped
public class EingabeController implements Serializable {

    @Inject
    private ContactsDAOBean contactsDAOBean;

    @Named
    @Produces
    private Contact newContact;

    @PostConstruct
    public void init() {
        this.newContact = new Contact();
    }

    public String save() {
        this.contactsDAOBean.save(this.newContact);
        log.info(this.newContact + " saved");
        this.savedContact = this.newContact;
        return "data";
    }

    @Named
    @Produces
    private Contact savedContact;

}

@Named和@RequestScoped注释已从联系人实体中删除.

The @Named and the @RequestScoped Annotations have been removed from the Contact eintity.

<h:inputText value="#{newContact.lastName}" styleClass="form-control" id="lastName"/>

页面的工作方式是这样,保存操作可以在没有错误的情况下调用.

The page works like this, the save action can be invoked without errro.

也许真正的原因是我对JSF和CDI应该如何工作的误解.

Maybe the real cause is a misunderstandig of mine how JSF and CDI are supposed to work.

我认为在原始版本中 -呈现页面时,实例化绑定到控件的Bean -Bean中填充了用户输入的值 -调用save操作时,将Bean注入到控制器中 好吧,这可能是我在推理中的错误:控制器已实例化 页面,并在那时注入了Contacts bean,那不是与绑定到控件的bean一样的实例吗?

I thought that in the original version - a bean which is bound to controls is instantiated when the page is rendered - the bean is filled with the values the user enters - when the save action is called the bean is injected in the controller well this might be my error in reasoning: the controller was instantiated with the page, and at that time the Contacts bean was injected, was that not the same instance like the bean bound to the controls?

我只是想(重新)学习JSF....有人可以推荐一个详尽地讨论JSF应用程序体系结构的好资源吗? 我想我有足够的书来单独讨论控件等.

I am just trying to (re-)learn JSF .... Can anybody recommend a good source which dicusses exhaustively the architecture of JSF applications? I guess I have enough books which discuss the controls etc. in isolation.

推荐答案

尝试如下编辑您的实体.

Try to edit your entity as in the following.

@Entity
@Table(name = "nameOfTableInDatabase", catalog = "databaseName")
@NamedQueries({
    @NamedQuery(name=Contact.FIND_ALL, query="SELECT c FROM Contact c"),
    @NamedQuery(name=Contact.DELETE_ALL, query="DELETE FROM Contact")
})
public class Contact implements java.io.Serializable {

bla
bla
}

这篇关于找不到JEE Web应用程序实体Wildfly的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆