[EJB 3.0] - Re: How to get this (very simple) tutorial to work in JBoss
by Hellek
I also found this (yesterday already) http://forum.java.sun.com/thread.jspa?threadID=5162297&tstart=60
but I just don't understand it.
They all have interfaces etc. and in the tutorial I tried to follow, they don't have such things at all.
In the tutorial they have:
1.) An EJB-Project with the persistence.xml and a Bean. The bean is just a "copy" of an existing table with getters and setters for all columns and the @Entity and @Id Annotations.
My persistence.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
| <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
| <persistence-unit name="EJBProject1">
| <provider>org.hibernate.ejb.HibernatePersistence</provider>
| <jta-data-source>java:/TestDS</jta-data-source>
| <class>com.Benutzer</class>
| <properties>
| <property name="hibernate.dialect"
| value="org.hibernate.dialect.MySQLDialect" />
| <property name="hibernate.transaction.manager_lookup_class"
| value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
| <property name="hibernate.hbm2ddl.auto" value="update"/>
| </properties>
| </persistence-unit>
| </persistence>
The datasource works fine, i.e. hibernate succesfully updates the table if I mess it up.
2.) A WebProject
With a servlet which looks like this:
| public class Servlet1 extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
|
| public Servlet1() {
| super();
| }
|
| @PersistenceUnit(name="EJBProject1")
| EntityManagerFactory emf;
|
| /* (non-Java-doc)
| * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
| */
| protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
| response.setContentType("text/html");
| response.setHeader("Pragma", "No-cache");
| response.setDateHeader("Expires", 0);
| response.setHeader("Cache-Control", "no-cache");
|
| List users = emf.createEntityManager().createQuery("select b from Benutzer b").getResultList();
| PrintWriter writer = response.getWriter();
|
| for (Iterator iterator = users.iterator(); iterator.hasNext();) {
| Benutzer benutzer = (Benutzer) iterator.next();
| writer.print(benutzer.getName());
| }
| writer.flush();
| writer.flush();
| }
| }
|
and a plain normal web.xml that just maps Servlet1 to an url
3.) Those 2 projects are then combined into an EARProject. Result is a .EAR-File with a jar for the Bean and a war for the webproject inside and the following application.xml
<?xml version="1.0" encoding="UTF-8"?>
| <application id="Application_ID" version="5.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_5_0.xsd">
| <display-name>
| EARProject1</display-name>
| <module>
| <web>
| <web-uri>WebProject2.war</web-uri>
| <context-root>WebProject2</context-root>
| </web>
| </module>
| <module>
| <ejb>EJBProject1.jar</ejb>
| </module>
| </application>
All 3 projects have a MANIFEST.MF that just says
| Manifest-Version: 1.0
| Class-Path:
|
I hope this illustrates the content very well, unfortunately I don't understand how to apply what people say in those topics about JNDI etc. onto this structure.
It would really be great if somebody could tell me how to do it.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4046539#4046539
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4046539
18 years, 11 months
[Beginners Corner] - How to use the @Factory annotation?
by mavoine
Hi,
I'm new to Seam and I'm trying to use the @Factory annotation to initialize the properties of a Managed Bean upon request of a jsf page, no matter if the request comes from a JSF context or not (ex. from another servlet).
My bean is super simple (see included code below), it only has 2 properties (postDate and postText) which need to be initialized to a value fetched from the database. I'd like to make the initialization take place when the page is requested using a Factory method (myFactory). The page gets displayed but the method myFactory is never called. What am I doing wrong?
Thanks!
Math
| ...
|
| @Name("newsBean")
| @Scope(ScopeType.SESSION)
| public class NewsBean implements Serializable {
|
| private static final long serialVersionUID = 1L;
| @In
| ToolbarBean toolbarBean;
| @In
| SessionBean sessionBean;
| @Out(required=false)
| Date postDate;
| @Out(required=false)
| String postText;
|
| public String process(){
|
| try {
| // update toolbar
| toolbarBean.setCurrentReport(ToolbarBean.CURRENT_REPORT_NOT_SET);
| toolbarBean.setPrinterFriendlyPath("/dynamic/faces/dataview/newsPF.jsf");
| toolbarBean.setShowExportToExcel(false);
| toolbarBean.setReportName(TextResource.getTextResourceString(new TextKey("News"),null,sessionBean.getCurrentLocale()));
| toolbarBean.setRefreshAction("newsBean.process");
|
| Language language = LanguageDAO.getInstance().findByPk(sessionBean.getLanguageCode());
| News news = NewsService.getInstance().findCurrentNews();
| postDate = news.getNewsTime();
| postText = news.getNewsDescription().getText(language);
|
| } catch (Exception ex){
| MessageHandler.handleGenericException(ex);
| return "error";
| }
|
| return "success";
| }
|
| @Factory("postDate")
| public void myFactory(){
| process();
| }
|
| ...
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4046532#4046532
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4046532
18 years, 11 months