[EJB 3.0] - How to create Rows in Database with EJB3.0 Entities - Proble
by Christian.Froihofer
Hi,
I don't have much experience in writing Entity Java Beans, so if some questions are "dummy-questions", I apologize for that.
Actual state: I have implemented Entity Java Beans with relationships between them. I can deploy them to JBOSS AS and everything is fine. Then, I want to implement a small client to fill the database with some values to check if my Beans are correct.
Problem: I have three Beans, that have relationships.
Entity Flight, Entity FlightSeat and Entity Address
Flight has a OneToMany relationship with FlightSeat and two ManyToOne relationships with Address (for start- and destinationaddress of the flight)
No, I want to create Values in the database with the Entities, but I don't know how I have to conside the relationships. How can I add a Flight row to the database? Do I have to specifiy the start- and destinationaddress, when saving the entity Flight with Entitymanager.persist()?? Maybe you know a good Tutorial where I can see, how it is possible to fill the tables?
Here my Implementation:
Flight.java:
|
| package at.ac.tuwien.inetappl.entity;
|
| import java.io.Serializable;
|
| import javax.persistence.CascadeType;
| import javax.persistence.Column;
| import javax.persistence.Entity;
| import javax.persistence.GeneratedValue;
| import javax.persistence.GenerationType;
| import javax.persistence.Id;
| import javax.persistence.JoinColumn;
| import javax.persistence.ManyToOne;
| import javax.persistence.OneToMany;
| import javax.persistence.Table;
| import javax.persistence.FetchType;
|
| import java.util.Date;
| import java.util.Collection;
|
| @Entity
| @Table (name="REL_FLIGHT")
| public class Flight implements Serializable{
|
| private long flightid;
| private String company;
| private Date duration;
| private Address startaddress;
| private Address destinationaddress;
| private Collection<FlightSeat> seats;
|
|
| public Flight() {}
|
|
| public Flight(String company, Date duration, Address startaddress, Address destinationaddress)
| {
| this.company=company;
| this.duration=duration;
| this.startaddress=startaddress;
| this.destinationaddress=destinationaddress;
|
| }
|
| @Id @GeneratedValue(strategy=GenerationType.AUTO)
| @Column(name="FLIGHT_ID")
| public long getId()
| {
| return this.flightid;
| }
|
| public void setId(long flightid)
| {
| this.flightid = flightid;
| }
|
| @Column(name="COMPANY")
| public String getCompany()
| {
| return this.company;
| }
|
| public void setCompany(String company)
| {
| this.company=company;
| }
|
| @Column(name="DURATION")
| public Date getDuration()
| {
| return this.duration;
| }
|
| public void setDuration(Date duration)
| {
| this.duration=duration;
| }
|
| @ManyToOne (optional=false)
| @JoinColumn(name = "START_ADDRESS_ID")
| public Address getStartAddress()
| {
| return this.startaddress;
| }
|
| public void setStartAddress(Address startaddress)
| {
| this.startaddress=startaddress;
| }
|
| @ManyToOne (optional=false)
| @JoinColumn(name = "DESTINATION_ADDRESS_ID")
| public Address getDestinationAddress()
| {
| return this.destinationaddress;
| }
|
| public void setDestinationAddress(Address destinationaddress)
| {
| this.destinationaddress=destinationaddress;
| }
|
| @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER, mappedBy="flight")
| //@JoinColumn(name= "SEAT_ID")
| public Collection<FlightSeat> getSeats()
| {
| return this.seats;
| }
|
| public void setSeats(Collection<FlightSeat> seats)
| {
| this.seats=seats;
| }
| }
|
Address.java:
|
| package at.ac.tuwien.inetappl.entity;
|
| import java.io.Serializable;
|
| import javax.persistence.Entity;
| import javax.persistence.GeneratedValue;
| import javax.persistence.GenerationType;
| import javax.persistence.Id;
| import javax.persistence.Table;
| import javax.persistence.Column;
|
| @Entity
| @Table (name="REL_ADDRESS")
| public class Address implements Serializable{
|
| private String land;
| private String city;
| private String street;
| private int streetnumber;
| private int postalcode;
| private long addressid;
|
| public Address() {}
|
| public Address (String land, String city, String street,
| int streetnumber, int postalcode) {
|
| this.land=land;
| this.city=city;
| this.street=street;
| this.streetnumber=streetnumber;
| this.postalcode=postalcode;
| }
|
| @Id @GeneratedValue(strategy=GenerationType.AUTO)
| @Column(name="ADDRESS_ID")
| public long getId()
| {
| return this.addressid;
| }
|
| public void setId(long addressid)
| {
| this.addressid = addressid;
| }
|
| @Column(name="LAND")
| public String getLand()
| {
| return this.land;
| }
|
| public void setLand(String land)
| {
| this.land=land;
| }
|
| @Column(name="CITY")
| public String getCity()
| {
| return this.city;
| }
|
| public void setCity(String city)
| {
| this.city=city;
| }
|
| @Column(name="STREET")
| public String getStreet()
| {
| return this.street;
| }
|
| public void setStreet(String street)
| {
| this.street=street;
| }
| @Column(name="STREETNUMBER")
| public int getStreetNumber()
| {
| return this.streetnumber;
| }
|
| public void setStreetNumber(int streetnumber)
| {
| this.streetnumber=streetnumber;
| }
| @Column(name="POSTALCODE")
| public int getPostalCode()
| {
| return this.postalcode;
| }
|
| public void setPostalCode(int postalcode)
| {
| this.postalcode=postalcode;
| }
| }
|
FlightSeat.java
| package at.ac.tuwien.inetappl.entity;
|
| import java.io.Serializable;
|
| import javax.persistence.Column;
| import javax.persistence.GeneratedValue;
| import javax.persistence.GenerationType;
| import javax.persistence.Id;
| import javax.persistence.Entity;
| import javax.persistence.JoinColumn;
| import javax.persistence.ManyToOne;
| import javax.persistence.Table;
|
| @Entity
| @Table (name="REL_FLIGHTSEAT")
| public class FlightSeat implements Serializable {
|
| private long seatid;
| private String category;
| private int price;
| private boolean available;
| private Flight flight;
|
| public FlightSeat() {}
|
| public FlightSeat(String category, int price, boolean available)
| {
| this.category=category;
| this.price=price;
| this.available=available;
| }
|
| @Id @GeneratedValue(strategy=GenerationType.AUTO)
| @Column(name="SEAT_ID")
| public long getId()
| {
| return this.seatid;
| }
|
| public void setId(long seatid)
| {
| this.seatid = seatid;
| }
|
| @Column(name="CATEGORY")
| public String getCategory()
| {
| return this.category;
| }
|
| public void setCategory(String category)
| {
| this.category=category;
| }
|
| @Column(name="PRICE")
| public int getPrice()
| {
| return this.price;
| }
|
| public void setPrice(int price)
| {
| this.price=price;
| }
|
| @Column(name="AVAILABLE")
| public boolean getAvailability()
| {
| return this.available;
| }
|
| public void setAvailability(boolean available)
| {
| this.available=available;
| }
|
| @ManyToOne()
| @JoinColumn(name="FLIGHT_ID")
| public Flight getFlight()
| {
| return this.flight;
| }
|
| public void setFlight(Flight flight)
| {
| this.flight=flight;
| }
| }
|
|
FlightBean.java - implementing business methods
| package at.ac.tuwien.inetappl.bean;
|
| import javax.ejb.Stateless;
| import javax.persistence.EntityManager;
| import javax.persistence.PersistenceContext;
| import javax.ejb.Remote;
|
| import at.ac.tuwien.inetappl.entity.Flight;
| import at.ac.tuwien.inetappl.entity.Address;
| import at.ac.tuwien.inetappl.entity.FlightSeat;
|
| import java.util.Collection;
| import java.util.Date;
| import java.util.Iterator;
| import java.io.Serializable;
| import javax.persistence.Query;
|
|
|
| @Stateless
| @Remote(FlightInterface.class)
| public class FlightBean implements FlightInterface, java.io.Serializable {
|
| //private Collection<Flight> flight;
|
| @PersistenceContext
| protected EntityManager em;
|
| /* CRUD METHODS FOR FLIGHT */
|
| /* CREATE FLIGHT */
|
| public void createFlight(String company, Date duration, Address start, Address dest)
| {
| Flight flight = new Flight();
| flight.setCompany(company);
| flight.setDuration(duration);
| flight.setStartAddress(start);
| flight.setDestinationAddress(dest);
| em.persist(flight);
| }
|
| public void updateFlight(Flight flight)
| {
|
| em.persist(flight);
|
| }
|
| /* DELETE FLIGHT*/
|
| public void deleteFlight(long id)
| {
|
| Query q = em.createQuery("DELETE FROM FLIGHT f WHERE f.FLIGHT_ID = :id");
| q.setParameter ("id", new Long(id));
|
| }
|
| /* SEARCH METHODS FOR FLIGHT */
|
| public Collection<Flight> getFlights()
| {
| return em.createQuery("from FLIGHT f").getResultList();
| }
|
| public Flight getFlight(long id) {
|
| Flight flight = em.find(Flight.class, new Long(id));
| return flight;
| }
|
| public String getCompany(long id) {
|
| Flight flight = em.find(Flight.class, new Long(id));
| String company = flight.getCompany();
| return company;
| }
| }
|
Thanks to all!! I hope, i can find help here!
Greetings,
redbaron
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3998727#3998727
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3998727
19 years, 3 months
[JBoss Seam] - Re: Seam portlet with Facelet support
by zeroconf
hi h.cahyadi
can you outline some main problems you discovered developing portlets using seam?
What do you mean by saying that you're not the decision maker - what would you choose - portlets (x)or seam?
My projects needs to integrate many different smaller applications with the ability to plugin new applications easily - so an portal environment can offers this.
I used plain JSF one and a half years ago to develop my first portlets - but this was sometimes really like a nightmare because especially when I was trying to use more than one JSF portlet per portal page - which is quite the normal case ..
(I have to admit that I used Liferay).
So now that I'm coming back to portals again I was hoping to find an new amazing framework which helps doing all the non-problem specific stuff and fastens building the actual business solution.
So - h.cahyadi - it sounds that you are quite more experienced using seam in a portal environment than I am -
do you (or anybody else) have any smaller portlet skeleton application which uses faceltes (an maybe some more seam specific stuff) which you might provide? or even some links to those or some tutorial because the portal seam example doesn't really satisfy me?
(For example no one answered to my former question concerning the example portlet http://jboss.com/index.html?module=bb&op=viewtopic&t=98250)
Regards
zeroconf
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3998726#3998726
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3998726
19 years, 3 months
[JBoss Seam] - Entity not persisting from within a Servlet Filter
by brentgfox
I'm attempting to integrate a servlet filter I wrote into a new seam application, and I can't seem to get it to persist an entity bean. I've created an EntityManager from an EntityManagerFactory, and can execute queries against it, but it doesn't seem to persist the data.
I've tried a few combinations - but to no avail.
>From my servlet filter:
| public void doFilter(ServletRequest request, ServletResponse response,
| FilterChain chain) throws IOException, ServletException
| {
| ...
| try
| {
| InitialContext ctx = new InitialContext();
| emf = (EntityManagerFactory) ctx.lookup("java:/userDatabase");
| EntityManager em = emf.createEntityManager();
| try
| {
| System.out.println("Attempting ejb query.");
| List existing = em.createQuery("from User").getResultList();
| Iterator ie = existing.iterator();
| while (ie.hasNext())
| {
| ie.next();
| System.out.println("Object Found");
| }
|
| // And the code that doesn't work.
| // User u = new User("tester");
| // em.persist(user);
|
|
| ...
|
And from my persistence.xml file
| ...
| <persistence-unit name="userDatabase">
| <provider>org.hibernate.ejb.HibernatePersistence</provider>
| <jta-data-source>java:/Postgres</jta-data-source>
| <properties>
| <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
| <property name="jboss.entity.manager.factory.jndi.name" value="java:/userDatabase"/>
| </properties>
| </persistence-unit>
| ...
|
And from my web.xml
| ...
| <!-- Persistence Context Ref -->
| <persistence-context-ref>
| <persistence-context-ref-name>persistence/UserDatabase</persistence-context-ref-name>
| <persistence-unit-name>userDatabase</persistence-unit-name>
| </persistence-context-ref>
| ...
|
The query returns objects - but when I attempt to persist the User entity - nothing happens. No exceptions, no results, no record in the database.
I'm running JBoss 4.0.5GA, with ejb3, Seam 1.1, connecting to a PostgreSQL 8.1 database.
Anyone have an idea why it will not persist?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3998712#3998712
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3998712
19 years, 3 months
[JBoss Seam] - Problem including commons-email in sample app
by mwilkowski
Hello,
I created and successfully deployed a sample app. I included commons-email and then the problems started. I get errors NoClassFound. I tried including commons-email.jar in war: WEB-INF/lib and then in the root dir of EAR itself. Unfortunately, I get the error below in both cases.
Below is the log sample:
17:08:49,986 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingC
ontextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
17:08:50,017 WARN [ServiceController] Problem starting service jboss.j2ee:service=EJB3,module=asterisk-admin.jar
java.lang.NoClassDefFoundError: org/apache/commons/mail/EmailException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2395)
at java.lang.Class.getDeclaredMethods(Class.java:1763)
at org.jboss.injection.InjectionUtil.processMethodAnnotations(InjectionUtil.java:96)
at org.jboss.injection.InjectionUtil.processAnnotations(InjectionUtil.java:172)
at org.jboss.ejb3.EJBContainer.processMetadata(EJBContainer.java:270)
at org.jboss.ejb3.SessionContainer.processMetadata(SessionContainer.java:116)
at org.jboss.ejb3.Ejb3Deployment.processEJBContainerMetadata(Ejb3Deployment.java:273)
at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:322)
at org.jboss.ejb3.Ejb3Module.startService(Ejb3Module.java:91)
at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
at $Proxy0.start(Unknown Source)
at org.jboss.system.ServiceController.start(ServiceController.java:417)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy37.start(Unknown Source)
at org.jboss.ejb3.EJB3Deployer.start(EJB3Deployer.java:449)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
at org.jboss.ws.integration.jboss.DeployerInterceptor.start(DeployerInterceptor.java:92)
at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java
:188)
at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy38.start(Unknown Source)
at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1015)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy6.deploy(Unknown Source)
at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:634)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:26
3)
at org.jboss.deployment.scanner.AbstractDeploymentScanner.startService(AbstractDeploymentScanner.java:336)
at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
at $Proxy0.start(Unknown Source)
at org.jboss.system.ServiceController.start(ServiceController.java:417)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy4.start(Unknown Source)
at org.jboss.deployment.SARDeployer.start(SARDeployer.java:302)
at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:766)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy5.deploy(Unknown Source)
at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:482)
at org.jboss.system.server.ServerImpl.start(ServerImpl.java:362)
at org.jboss.Main.boot(Main.java:200)
at org.jboss.Main$1.run(Main.java:490)
at java.lang.Thread.run(Thread.java:595)
17:08:50,017 INFO [EJB3Deployer] Deployed: file:/C:/java/jboss-4.0.5.GA/server/default/tmp/deploy/tmp477asterisk-admin.
ear-contents/asterisk-admin.jar
17:08:50,017 INFO [TomcatDeployer] deploy, ctxPath=/asterisk-admin, warUrl=.../tmp/deploy/tmp477asterisk-admin.ear-cont
ents/asterisk-admin-exp.war/
17:08:50,126 INFO [ServletContextListener] Welcome to Seam 1.0.1.GA
17:08:50,142 INFO [Initialization] reading components.xml
17:08:50,220 INFO [Initialization] reading properties from: /seam.properties
17:08:50,220 INFO [Initialization] reading properties from: /jndi.properties
17:08:50,220 INFO [Initialization] initializing Seam
Below is the code of the stateless session bean (very simple one) using commons-email:
package com.wolainfo.asterisk.user;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
import org.apache.log4j.Logger;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.core.FacesMessages;
/**
* Class responsible for user management
*
* @author Michal Wilkowski
*
*/
@Stateless
@Name("userManager")
public class UserManagerBean implements UserManager {
private static Logger log = Logger.getLogger(UserManagerBean.class);
//TODO: email suffix should be a subject to IoC
private String defaultEmailSuffix = "@wolainfo.com.pl";
@In @Out
private User user;
@PersistenceContext
private EntityManager em;
public EntityManager getEm() {
return em;
}
public void setEm(EntityManager em) {
this.em = em;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
/**
* Checks user against LDAP. Not implemented yet.
* @param userName User name to check
* @return FUTURE: True if exists, false - otherwise. PRESENT: As the function is
* not implemented yet it always returns true.
*/
public boolean existsInLDAP(String userName)
{
return true;
}
/**
* Returns user from the local database
*
* @param userName
* @return
*/
public User getUser(String userName)
{
assert userName != null;
Query query = em.createQuery("from User where username = :username");
query.setParameter("username", user.getUsername());
List userList = query.getResultList();
if (userList.size() == 1)
{
return userList.get(0);
}
else if ((userList.size() > 1) || (userList.size() < 0))
{
throw new IllegalStateException("userList.size() = " + userList.size() + " while it should be 0 or 1");
}
else
{
return null;
}
}
/**
* Registers user within the Asterisk SIP users database and sends
* automatically generated password to the user. User is checked against LDAP
*
* @param userName
* @return
*/
public boolean register(String userName)// throws EmailException
{
assert userName != null;
if (existsInLDAP(userName))
{
log.debug("User " + userName + " found in LDAP. Searching database");
User user = getUser(userName);
if (user != null)
{
log.debug("User " + userName + " not found in database. Creating new account");
user = create(userName);
assert user != null;
}
sendPassword(user);
return true;
}
else
{
log.warn("User " + userName + " not found in database. Cannot register");
return false;
}
}
/**
* Sends password notification to the user
*
* @param user
*/
public void sendPassword(User user)// throws EmailException
{
try
{
//TODO: should use IoC
SimpleEmail simpleEmail = new SimpleEmail();
simpleEmail.setHostName("zefir.wolainfo.com.pl");
simpleEmail.setFrom("asterisk(a)wolainfo.com.pl");
simpleEmail.setSubject("Login i haslo");
simpleEmail.addTo(user.getEmail());
simpleEmail.setMsg("Twoj login: " + user.getUsername() + ". Twoje haslo: " + user.getPassword());
}
catch(EmailException e)
{
log.error("",e);
}
}
/**
* Creates a user account. A password is randomly generated. It assumes that e-mail is @wolainfo.com.pl
* @return Newly created account
*/
public User create(String userName)
{
log.debug("Creating user " + userName);
User user = new User();
user.setUsername(userName);
user.setPassword(generatePassword(userName));
user.setEmail(userName + getDefaultEmailSuffix());
em.persist(user);
log.debug("User (" + user.toString() + ") has just been created");
return user;
}
/**
* Generates password.
* @param userName
* @return
*/
public String generatePassword(String userName)
{
//TODO: requires coding using DES
return "pwd_" + userName;
}
public String getDefaultEmailSuffix() {
return defaultEmailSuffix;
}
public void setDefaultEmailSuffix(String defaultEmailSuffix) {
this.defaultEmailSuffix = defaultEmailSuffix;
}
/**
* Registers user account
*
* @return
*/
public String register()
{
boolean result = register(user.getUsername());
if (result)
{
return "/registered.jsp";
}
else
{
FacesMessages.instance().add("Username does not exist");
return null;
}
}
}
Do you have any idea what might be wrong???
Thanks
Michal
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3998710#3998710
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3998710
19 years, 3 months
[JBoss jBPM] - Re: Assign-copy problem, very strange!
by pkovgan
Alex, and still it is strange!
my wsdl :
<complexType name="CustomerRootWrapper">
| ?
| <sequence>
| <element maxOccurs="unbounded" minOccurs="0" name="customerRootBillToAddress" nillable="true" type="tns:CustomerRootBillToAddressWrapper"/>
| <element maxOccurs="unbounded" minOccurs="0" name="customerRootContactPersons" nillable="true" type="tns:CustomerRootContactPersonsWrapper"/>
| <element maxOccurs="unbounded" minOccurs="0" name="customerRootShipToAddress" nillable="true" type="tns:CustomerRootShipToAddressWrapper"/>
| <element name="description" nillable="true" type="string"/>
| <element name="id" nillable="true" type="string"/>
| <element name="name" nillable="true" type="string"/>
| </sequence>
| </complexType>
as you can see description , id, and name are all NOT optional, but only description throws an arror, name is pretty quiet. it still seems to me unlogical.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3998695#3998695
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3998695
19 years, 3 months