简体   繁体   English

从独立的Web应用程序(netbeans)调用ejb实体类

[英]Call an ejb entity class from an independent web application (netbeans)

I'm making a small webshop application for school in Netbeans. 我正在为Netbeans的学校制作一个小型网上商店应用程序。 I have a Customer entity class in an EJB module together with a local session bean and a remote session bean. 我在EJB模块中有一个Customer实体类,还有一个本地会话bean和一个远程会话bean。

Next I have an independent web application, which can of course call the remote session bean. 接下来,我有一个独立的Web应用程序,它当然可以调用远程会话Bean。

From the application I can call a method in the remote session bean to give me all customers. 从应用程序中,我可以在远程会话bean中调用一个方法来给我所有客户。 But what should the session bean return? 但是会话bean应该返回什么?

  • It can return a list of Customers but my application does not know the customer class. 它可以返回客户列表,但是我的应用程序不知道客户类别。 Should I add a jar of my ejb module in the application? 是否应在应用程序中添加一罐ejb模块?
  • I could return a list of lists with all information of the customers but this is not very nice. 我可以返回包含客户所有信息的列表的列表,但这不是很好。
  • I have read something here about having a Customer interface in the web application but I don't understand how this works. 我在这里阅读了一些有关在Web应用程序中具有客户界面的信息,但我不知道这是如何工作的。
  • Would it help making a Enterprise application and adding both the jar of the ejb module and the war of the web application? 它会有助于制作企业应用程序并添加ejb模块的jar和Web应用程序的作用吗?

What's the best choice? 最好的选择是什么?

(Oh and I'm using wicket as framework, if that has anything to do with this) (哦,我正在使用检票口作为框架,如果与此有关的话)

EDIT: 编辑:

So my setup is like this : 所以我的设置是这样的:

  • a library containing the entity class and the interface of the remote bean 一个包含实体类和远程bean接口的库
  • a ejb module containing the remote bean and a facade of the entity class, it also has the library above 一个ejb模块,其中包含远程bean和实体类的外观,并且上面还有一个库
  • a web application: also has the library 一个Web应用程序:也有该库
  • a enterprise application containing the ejb-jar and the war. 包含ejb-jar和war的企业应用程序。

It's not working though. 虽然没有用。 When I deploy the ear, I get this error: 当我展开耳朵时,出现以下错误:

Error in annotation processing: java.lang.NoClassDefFoundError: shop2/database/customer/CustomerBeanRemote

I'm not sure where to put the persistence file. 我不确定将持久性文件放在何处。 Now it is in the ejb module. 现在它在ejb模块中。 But I don't think this is actually the problem. 但是我不认为这实际上是问题所在。

Can you maybe guide me through how to make the project. 您能否指导我完成该项目。 It is the first time I work with EJB and Java EE. 这是我第一次使用EJB和Java EE。

Thanks! 谢谢!

You must create a client project contain all your entities and interfaces, and use this project in the EJB module and web project. 您必须创建一个包含所有实体和接口的客户端项目,并在EJB模块和Web项目中使用该项目。

In this case you can return a list of customer to the web project by using the remote interface 在这种情况下,您可以使用远程界面将客户列表返回到Web项目

Of course, you must deploy the ejb project + the client project in an ear project. 当然,您必须在耳朵项目中部署ejb项目+客户端项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM