[JBoss Seam] - Re: Restrict
by tony.herstellï¼ gmail.com
| package nz.co.risingstars.content;
|
| import java.io.ByteArrayOutputStream;
| import java.io.IOException;
| import java.io.InputStream;
|
| import javax.servlet.ServletException;
| import javax.servlet.http.HttpServlet;
| import javax.servlet.http.HttpServletRequest;
| import javax.servlet.http.HttpServletResponse;
|
| import nz.co.risingstars.entities.Image;
|
| import org.jboss.seam.Component;
|
| /**
| * Serves images and other member content
| *
| * @author Shane Bryzak
| */
| public class ContentServlet extends HttpServlet {
|
| private static final String IMAGES_PATH = "/images";
|
| private byte[] noImage;
|
| public ContentServlet() {
| InputStream noImageFromStorage = getClass().getResourceAsStream("/images/no_image.png");
| if (noImageFromStorage != null) {
| ByteArrayOutputStream out = new ByteArrayOutputStream();
| byte[] buffer = new byte[512];
| try {
| int read = noImageFromStorage.read(buffer);
| while (read != -1) {
| out.write(buffer, 0, read);
| read = noImageFromStorage.read(buffer);
| }
|
| noImage = out.toByteArray();
| } catch (IOException e) {
| }
| }
| }
|
| @Override
| protected void doGet(HttpServletRequest request,
| HttpServletResponse response) throws ServletException, IOException {
|
| if (IMAGES_PATH.equals(request.getPathInfo())) {
| ContentController contentController = (ContentController) Component
| .getInstance(ContentControllerImpl.class);
|
| String id = request.getParameter("id");
| Image imageToFetch = null;
| if (id != null && !"".equals(id)) {
| imageToFetch = contentController.getImage(Long.parseLong(id));
| }
|
| String contentType = null;
| byte[] data = null;
|
| if (imageToFetch != null && imageToFetch.getThumbnail() != null && imageToFetch.getThumbnail().length > 0) {
| contentType = imageToFetch.getType();
| data = imageToFetch.getThumbnail();
| } else if (noImage != null) {
| contentType = "image/png";
| data = noImage;
| }
|
| if (data != null) {
| response.setContentType(contentType);
| }
| response.getOutputStream().write(data);
| response.getOutputStream().flush();
| }
| }
| }
|
|
| package nz.co.risingstars.content;
|
| import nz.co.risingstars.entities.Image;
|
| public interface ContentController
| {
| Image getImage(long imageId);
| }
|
|
| package nz.co.risingstars.content;
|
| import javax.ejb.Stateless;
| import javax.persistence.EntityManager;
| import javax.persistence.PersistenceContext;
|
| import nz.co.risingstars.entities.Image;
|
| import org.jboss.seam.annotations.Name;
|
| @Stateless
| @Name("contentController")
| public class ContentControllerImpl implements ContentController {
|
| @PersistenceContext
| private EntityManager em;
|
| public Image getImage(long imageId) {
| Image img = em.find(Image.class, imageId);
|
| // if (img == null || !Identity.instance().hasPermission("memberImage", "view", img))
| // return null;
| // else
| return img;
| }
| }
|
|
|
|
|
|
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4016700#4016700
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4016700
19Â years, 2Â months
[JBoss Seam] - Re: Restrict
by tony.herstellï¼ gmail.com
Ugh.. its a bit crappy at the moment...
but here it is:
1. Don't use the progress viewer as that just goes SPLAT (I don't think IceFaces passes to the callback it makes the actual conversationId so you get a "not part of long running conversation" exception.
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
| <html xmlns="http://www.w3.org/1999/xhtml"
| xmlns:h="http://java.sun.com/jsf/html"
| xmlns:ui="http://java.sun.com/jsf/facelets"
| xmlns:f="http://java.sun.com/jsf/core"
| xmlns:s="http://jboss.com/products/seam/taglib"
| xmlns:ice="http://www.icesoft.com/icefaces/component">
| <head>
| <meta http-equiv="Content-Type"
| content="text/html; charset=iso-8859-1" />
| <link rel="stylesheet" type="text/css" href="./css/risingstars.css" />
| <link rel="stylesheet" type="text/css" href="./xmlhttp/css/xp/xp.css" />
| <title>Upload</title>
| </head>
| <body>
|
| <ui:composition xmlns="http://www.w3.org/1999/xhtml"
| xmlns:ui="http://java.sun.com/jsf/facelets"
| xmlns:h="http://java.sun.com/jsf/html"
| xmlns:f="http://java.sun.com/jsf/core"
| xmlns:s="http://jboss.com/products/seam/taglib"
| xmlns:ice="http://www.icesoft.com/icefaces/component"
| template="template.xhtml">
|
| <!-- content -->
| <ui:define name="title">
| <ice:outputText value="#{messages.form_upload}" />
| </ui:define>
| <ui:define name="content">
|
| <ice:form>
| <ice:panelGrid columns="1">
| <fieldset>
| <legend>
| <ice:outputText value="#{messages.fieldset_upload}" />
| </legend>
| <!-- Messages -->
| <ice:panelGrid columns="1">
| <ice:messages infoClass="error" globalOnly="true" />
| </ice:panelGrid>
|
| <ice:panelGrid columns="1">
| <fieldset>
| <legend>
| <ice:outputText value="#{messages.fieldset_upload}"/>
| </legend>
|
| <ice:panelGrid columns="1">
| <ice:inputFile style="border:none; width:400px; height:70px;"
| actionListener="#{uploadController.action}"/> <!-- progressListener="#{uploadController.progress}" -->
| <ice:outputProgress id="progress" value="#{uploadController.percent}"/>
| </ice:panelGrid>
|
| <ice:panelGrid columns="1" width="100%">
| <div align="right">
| <ice:commandButton action="#{uploadController.cancel}"
| value="#{messages.button_cancel}" immediate="true"
| type="submit" />
| <ice:commandButton id="done" type="submit"
| value="#{messages.button_done}" immediate="true"
| action="#{uploadController.done}" />
| </div>
| </ice:panelGrid>
|
| </fieldset>
| </ice:panelGrid>
|
| </fieldset>
| </ice:panelGrid>
| </ice:form>
|
| </ui:define>
| <!-- content -->
| </ui:composition>
|
| </body>
|
| </html>
|
|
For the backing bean I stole the code from the seamspace example (Who Hoo!)... (well I am not THAT stupid!)
So... add this to your web.xml:
|
| <!-- Content Servlet -->
|
| <servlet>
| <servlet-name>Content Servlet</servlet-name>
| <servlet-class>nz.co.risingstars.content.ContentServlet</servlet-class>
| </servlet>
|
| <servlet-mapping>
| <servlet-name>Content Servlet</servlet-name>
| <url-pattern>/content/*</url-pattern>
| </servlet-mapping>
|
| <filter>
| <filter-name>Seam Servlet Filter</filter-name>
| <filter-class>org.jboss.seam.servlet.SeamServletFilter</filter-class>
| </filter>
|
| <filter-mapping>
| <filter-name>Seam Servlet Filter</filter-name>
| <url-pattern>/content/*</url-pattern>
| </filter-mapping>
|
| <!-- file upload Servlet -->
| <servlet>
| <servlet-name>uploadServlet</servlet-name>
| <servlet-class>com.icesoft.faces.component.inputfile.FileUploadServlet</servlet-class>
| <load-on-startup> 1 </load-on-startup>
| </servlet>
|
| <servlet-mapping>
| <servlet-name>uploadServlet</servlet-name>
| <url-pattern>/uploadHtml</url-pattern>
| </servlet-mapping>
|
|
Now to handle the stuff coming in... here is the code...
with the following hack(s):
action is called when the image is uploaded... since you can't pass back a new state to "go to" you are stuffed for now as moving away from the page screws things up..
I tried adding a DONE button to the gui that called my "done" routine but thats crashes... so I hack the action success route to call Done Instead (OUCH!)...
This leaves a transaction incomplete however... HACK!
I then have to quite the browser and run up a new browser (usually) to see the results when I look at my list of xxx's (users or orgs).
Hackity Hackity Hack.
Not long till you get all things going wrong as something barfs over the "hanging" transaction or Hibernate reports a Heap Space error..
| package nz.co.risingstars.actions.upload;
|
| import javax.faces.event.ActionEvent;
| import java.util.EventObject;
|
| /**
| * @author Tony Herstell
| * @version $Revision: 1.3 $ $Date: 2007-02-12 22:28:39 $
| */
| public interface UploadController {
|
| public String startUpload(Object selectedObject);
|
| public void setPercent(int percent);
|
| public int getPercent();
|
| public void action(ActionEvent event);
|
| public void progress(EventObject event);
|
| public String done();
|
| public String cancel();
|
| public void destroy();
| }
|
| package nz.co.risingstars.actions.upload;
|
| import static javax.persistence.PersistenceContextType.EXTENDED;
|
| import com.icesoft.faces.component.inputfile.InputFile;
| import com.icesoft.faces.webapp.xmlhttp.PersistentFacesState;
| import com.icesoft.faces.webapp.xmlhttp.RenderingException;
|
| import javax.ejb.Remove;
| import javax.ejb.Stateful;
| import javax.ejb.TransactionAttribute;
| import javax.ejb.TransactionAttributeType;
| import javax.faces.event.ActionEvent;
| import javax.imageio.ImageIO;
| import javax.persistence.EntityManager;
| import javax.persistence.PersistenceContext;
| import javax.swing.ImageIcon;
|
| import nz.co.risingstars.actions.organisation.FindOrganisationController;
| import nz.co.risingstars.actions.user.FindUserController;
| import nz.co.risingstars.entities.Image;
| import nz.co.risingstars.entities.Organisation;
| import nz.co.risingstars.entities.User;
|
| import org.jboss.seam.Component;
| import org.jboss.seam.annotations.Begin;
| import org.jboss.seam.annotations.Conversational;
| import org.jboss.seam.annotations.Destroy;
| import org.jboss.seam.annotations.End;
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Logger;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.core.Conversation;
| import org.jboss.seam.core.FacesMessages;
| import org.jboss.seam.log.Log;
|
| import java.awt.Graphics2D;
| import java.awt.RenderingHints;
| import java.awt.image.BufferedImage;
| import java.io.BufferedInputStream;
| import java.io.BufferedOutputStream;
| import java.io.ByteArrayOutputStream;
| import java.io.File;
| import java.io.FileInputStream;
| import java.io.IOException;
| import java.io.InputStream;
| import java.io.OutputStream;
| import java.util.EventObject;
|
| /**
| * @author Tony Herstell
| * @version $Revision: 1.4 $ $Date: 2007-02-13 04:46:40 $
| */
| @Stateful
| @Name("uploadController")
| @Conversational
| public class UploadControllerImpl implements UploadController {
|
| /**
| * The maximum width allowed for image rescaling
| */
| private static final int MAX_IMAGE_WIDTH = 1024;
|
| @PersistenceContext(type = EXTENDED)
| private EntityManager em;
|
| @Logger
| private Log log;
|
| @In(required = false)
| private Conversation conversation;
|
| @In(create = true)
| private transient FacesMessages facesMessages;
|
| private enum ParentObjectKind {ORGANISATION, USER};
| private ParentObjectKind parentObjectKind = null;
| private long primaryKey;
|
| private int percent = -1;
| private PersistentFacesState state = null;
|
| private Image image = null;
|
| @Begin
| @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
| public String startUpload(Object selectedObject) {
| log.info("> startUpload");
| String theValueToBeReturned = null;
| state = PersistentFacesState.getInstance();
| if (selectedObject instanceof Organisation) {
| parentObjectKind = ParentObjectKind.ORGANISATION;
| primaryKey = ((Organisation)selectedObject).getId();
| log.info("Organisation Id was =>" + primaryKey);
| theValueToBeReturned = "upload";
| } else if (selectedObject instanceof User) {
| parentObjectKind = ParentObjectKind.USER;
| primaryKey = ((User)selectedObject).getId();
| log.info("User Id was =>" + primaryKey);
| theValueToBeReturned = "upload";
| } else {
| log.error("upload called with object type not supported.");
| }
| logConversation("Upload");
| log.info("< startUpload");
| return theValueToBeReturned;
| }
|
| @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
| public void setPercent(int percent) {
| log.info("> setPercent");
| this.percent = percent;
| log.info("< setPercent");
| }
|
| @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
| public int getPercent() {
| log.info("> getPercent");
| log.info("< getPercent");
| return percent;
| }
|
| //(a)TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
| @TransactionAttribute(TransactionAttributeType.REQUIRED)
| public void action(ActionEvent event) {
| log.info("> action");
| InputFile inputFile = (InputFile) event.getSource();
| if (inputFile.getStatus() == InputFile.SAVED) {
| String fileName = inputFile.getFileInfo().getFileName();
| String contentType = inputFile.getFileInfo().getContentType();
|
| File file = inputFile.getFile();
| byte[] inputFileAsBytes = getFileAsBytes(file);
|
| // Check if the image needs to be rescaled
| int width = Math.min(MAX_IMAGE_WIDTH, 70);
| ImageIcon icon = new ImageIcon(inputFileAsBytes);
| boolean rescale = false;
| if (width > 0 && width != icon.getIconWidth()) {
| rescale = true;
| }
|
| byte[] inputFileAsThumbnailAsBytes = null;
| // Rescale the image if required
| if (rescale) {
| inputFileAsThumbnailAsBytes = getRescaledImageAsBytes(contentType, width, icon);
| } else {
| inputFileAsThumbnailAsBytes = inputFileAsBytes;
| }
| Image image = (Image)Component.getInstance("image", true);
| image.setName(fileName);
| image.setType(contentType);
| image.setThumbnail(inputFileAsThumbnailAsBytes);
| image.setImage(inputFileAsBytes);
| image.setVersion(0);
| this.image = image;
|
| } else if (inputFile.getStatus() == InputFile.INVALID) {
| inputFile.getFileInfo().getException().printStackTrace();
| } else if (inputFile.getStatus() == InputFile.SIZE_LIMIT_EXCEEDED) {
| inputFile.getFileInfo().getException().printStackTrace();
| } else if (inputFile.getStatus() == InputFile.UNKNOWN_SIZE) {
| inputFile.getFileInfo().getException().printStackTrace();
| }
| done(); // HACK!
| log.info("< action");
| }
|
| @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
| private byte[] getFileAsBytes(File file) {
| byte[] valueToReturn = null;
| log.info("> getAsBytes");
| InputStream in = null;
| OutputStream out = null;
| try {
| in = new BufferedInputStream(new FileInputStream(file));
| ByteArrayOutputStream baos = new ByteArrayOutputStream();
| out = new BufferedOutputStream(baos);
|
| final int toRead = 1024;
| byte[] buffy = new byte[toRead];
| int read;
|
| while ((read = in.read(buffy)) != -1) {
| out.write(buffy, 0, read);
| out.flush();
| }
|
| valueToReturn = baos.toByteArray();
|
| } catch (IOException e) {
| throw new IllegalStateException(e.getMessage());
| } finally { // Try to release any resources.
|
| try {
| if (in != null) {
| in.close();
| }
| } catch (IOException ignored) {}
|
| try {
| if (out != null) {
| out.close();
| }
| } catch (IOException ignored) {}
| }
| log.info("< getAsBytes");
| return valueToReturn;
| }
|
| @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
| private byte[] getRescaledImageAsBytes(String contentType , int width, ImageIcon icon) {
| double ratio = (double) width / icon.getIconWidth();
| int height = (int) (icon.getIconHeight() * ratio);
|
| int imageType = "image/png".equals(contentType) ? BufferedImage.TYPE_INT_ARGB
| : BufferedImage.TYPE_INT_RGB;
| BufferedImage bImg = new BufferedImage(width, height, imageType);
| Graphics2D g2d = bImg.createGraphics();
| g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
| RenderingHints.VALUE_INTERPOLATION_BICUBIC);
| g2d.drawImage(icon.getImage(), 0, 0, width, height, null);
| g2d.dispose();
|
| String formatName = "";
| if ("image/png".equalsIgnoreCase(contentType))
| formatName = "png";
| else if ("image/jpeg".equalsIgnoreCase(contentType))
| formatName = "jpeg";
| else if ("image/jpg".equalsIgnoreCase(contentType))
| formatName = "jpg";
| else if ("image/gif".equalsIgnoreCase(contentType))
| formatName = "gif";
|
| ByteArrayOutputStream baos = null;
| OutputStream out = null;
| try {
| baos = new ByteArrayOutputStream();
| out = new BufferedOutputStream(baos);
| try {
| ImageIO.write(bImg, formatName, out);
| } catch (IOException e) {
| e.printStackTrace();
| }
| } finally { // Try to release any resources.
| try {
| if (baos != null) {
| baos.close();
| }
| } catch (IOException ignored) {}
| try {
| if (out != null) {
| out.close();
| }
| } catch (IOException ignored) {}
| }
| return baos.toByteArray();
| }
|
| @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
| public void progress(EventObject event) {
| log.info("> progress");
| InputFile file = (InputFile) event.getSource();
| this.percent = file.getFileInfo().getPercent();
| try {
| if (state != null) {
| state.render();
| } else {
| System.out.println("state is null");
| }
| } catch (RenderingException ee) {
| System.out.println(ee.getMessage());
| }
| log.info("< progress");
| }
|
| //@End
| //(a)TransactionAttribute(TransactionAttributeType.REQUIRED)
| public String done() {
| log.info("> done");
| String valueToReturn = null;
|
| em.persist(image);
| if (parentObjectKind == ParentObjectKind.ORGANISATION) {
| Organisation organisationToBeUploadedTo = em.find(Organisation.class, primaryKey);
| if (organisationToBeUploadedTo == null) {
| log.warn("Organisation to be Uploaded to is not found." + primaryKey);
| } else {
| organisationToBeUploadedTo.setPicture(image);
| em.persist(organisationToBeUploadedTo);
| em.flush();
| FindOrganisationController findOrganisationController = (FindOrganisationController)Component.getInstance("findOrganisationController", false);
| if (findOrganisationController != null) {
| // We have to inform the Stateful findOrganisationController that one of its children has been updated.
| findOrganisationController.updateOrganisationInExistingList(organisationToBeUploadedTo);
| }
| facesMessages.addFromResourceBundle("organisation_picture_added");
| valueToReturn = "findOrganisation";
| }
| } else if (parentObjectKind == ParentObjectKind.USER) {
| User userToBeUploadedTo = em.find(User.class, primaryKey);
| if (userToBeUploadedTo == null) {
| log.warn("User to be Uploaded to is not found." + primaryKey);
| } else {
| userToBeUploadedTo.setPicture(image);
| em.persist(userToBeUploadedTo);
| em.flush();
| FindUserController findUserController = (FindUserController)Component.getInstance("findUserController", false);
| if (findUserController != null) {
| // We have to inform the Stateful findUserController that one of its children has been updated.
| findUserController.updateUserInExistingList(userToBeUploadedTo);
| }
| facesMessages.addFromResourceBundle("user_picture_added");
| valueToReturn = "findUser";
| }
| } else {
| log.error("done called with object type not supported.");
| }
|
| log.info("< done");
| return valueToReturn;
| }
|
| @End
| @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
| public String cancel() {
| log.info("> cancel");
| String valueToReturn = null;
| if (parentObjectKind == ParentObjectKind.ORGANISATION) {
| valueToReturn = "findOrganisation";
| } else if (parentObjectKind == ParentObjectKind.USER) {
| valueToReturn = "findUser";
| } else {
| log.error("cancel called with object type not supported.");
| }
| log.info("< cancel");
| return valueToReturn;
| }
|
| @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
| private void logConversation(String name) {
| log.info("Starting " + name + " conversation.");
| if (conversation != null) {
| log.info("Conversation. (" + conversation.getId() + ")");
| }
| }
|
| @Remove
| @Destroy
| @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
| public void destroy() {
| log.info("> destroy");
| log.info("< destroy");
| }
|
| }
|
It's going to be sorted out in the next IceFaces release of course ;).. It would be nice to hand over the project with all my hack removed to IceFaces and the next release be dependent on all this code working; but thats pretty unlikely... so I asked for an Alpha of their next release asap!
You will notice I do some image manipulation to store a thunbmnail with the main image.. which SEEMS to work (visually), but until I get this stable.. then I don't really know.
I aim to post this complete project to the wiki when its actually working well enough (post some nasty IceFaces bugs)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4016698#4016698
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4016698
19Â years, 2Â months
[JBoss Seam] - Views within views
by lightbulb432
I need to have XHTML views containing other views using the templating features of Facelets. e.g. view "outside.xhtml" contains views "inside1.xhtml" and "inside2.xhtml".
However, because each view can also be seen as a standalone view, I'm concerned about conflicts in the injected/outjected components that may not be evident initially. Does such a risk exist? e.g. inside1.xhtml outjects a value that gets overridden by inside2.xhtml. Or was Seam designed to handle such things, where variables are kept apart (e.g. DataModels, DataModelSelections...)
The next issue is with navigation. In pages.xml, which view would you mention for a link clicked in inside1.xhtml - would it be outside.xhtml, or inside1.xhtml? (Keeping in mind that the address bar would of course show outside.xhtml)
Any other potential troubles here?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4016692#4016692
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4016692
19Â years, 2Â months
[Persistence, JBoss/CMP, Hibernate, Database] - em.refresh() throwing error in JBoss AS 4.0.5.GA
by tnevaker
I am using a stateful EJB to manage user sessions on a web app, and manage the state of an Employee entity EJB that contains the user's information. The user information is returned as a bean by calling the getUserBean() method of the stateful EJB, which first attempts to use the persistence manager refresh() method, then creates and returns a bean object with the updated data.
This code was working in JBoss 4.0.4.GA, but I am now deploying to JBoss 4.0.5.GA and it is now throwing a "java.lang.IllegalArgumentException: Entity not managed" error. The error is being caused by the call to the refresh() method of the EntityManager. Does anybody know why this code no longer runs in 4.0.5.GA, or what needs to be changed to get it running in the latest version?
Here is the relevant code:
UserSessionFacadeBean.java - I have traced the error to the em.refresh() call bolded below:
@Stateful(name="UserSessionFacade")
| public class UserSessionFacadeBean implements UserSessionFacadeRemote,
| UserSessionFacadeLocal {
| @PersistenceContext(unitName="warehaus")
| protected EntityManager em;
|
| private Employee _user;
| private boolean _initialized = false;
|
| public UserSessionFacadeBean() {
| }
|
| public void initializeUser(String userId) {
| Collection<Employee> rsEmployee =
| em.createNamedQuery("findEmployeeByUserId").setParameter("userId", userId).getResultList();
|
| if (rsEmployee.size() == 1) {
| Iterator<Employee> iter = rsEmployee.iterator();
| if (iter.hasNext()) {
| this._user = iter.next();
| _initialized = true;
| }
| }
| }
|
| public UserBean getUserBean() {
| UserBean userBean = new UserBean();
|
| if (_initialized) {
| // Refresh the Employee entity
| em.refresh(_user);
|
| userBean.setEmployeeId(_user.getEmployeeId());
| userBean.setUserId(_user.getUserId());
| userBean.setFullName(_user.getFirstName() + " " + _user.getLastName());
| userBean.setFirstName(_user.getFirstName());
| userBean.setMiddleInitial(_user.getMiddleInitial());
| userBean.setLastName(_user.getLastName());
| userBean.setEmailAddress(_user.getEmailAddress());
| userBean.setAkoEmailAddress(_user.getAkoEmailAddress());
| userBean.setRecStatusFlag(_user.getRecStatusFlag());
| userBean.setRoles(_user.getRoles());
| userBean.setPermissions(_user.getPermissions());
| userBean.setApplications(getUserApplications());
| }
|
| return userBean;
| }
| }
Employee.java
@Entity
| @NamedQueries({
| @NamedQuery(name="findAllEmployee",
| query="select object(o) from Employee o"),
| @NamedQuery(name="findEmployeeByUserId",
| query="select object(o) from Employee o where upper(o.userId) = upper(:userId)")
| })
| @Table(name="EI")
| public class Employee implements Serializable {
| // class code...
| }
persistence.xml
<persistence 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"
| version="1.0">
| <persistence-unit name="warehaus" transaction-type="JTA">
| <provider>org.hibernate.ejb.HibernatePersistence</provider>
| <jta-data-source>java:/warehausDS</jta-data-source>
| <class>mypackage.Employee</class>
| ... other class entries ...
| <properties>
| <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/>
| </properties>
| </persistence-unit>
| </persistence>
And here is the stack trace on the error that is returned.
javax.ejb.EJBException: java.lang.IllegalArgumentException: Entity not managed
| at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
| at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
| at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:83)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
| at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:102)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.stateful.StatefulContainer.localInvoke(StatefulContainer.java:203)
| at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:98)
| at $Proxy102.getUserBean(Unknown Source)
| 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 coldfusion.runtime.StructBean.invoke(StructBean.java:326)
| at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:1650)
| at cfusertest2ecfm474474188.runPage(C:\jboss-4.0.5.GA\server\default\.\deploy\cfusion.ear\cfusion.war\earltest\cftest\usertest.cfm:110)
| at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:147)
| at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:357)
| at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:62)
| at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:107)
| at coldfusion.filter.PathFilter.invoke(PathFilter.java:80)
| at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:47)
| at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
| at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:35)
| at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:43)
| at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
| at coldfusion.CfmServlet.service(CfmServlet.java:105)
| at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
| at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
| at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
| at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
| at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
| at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
| at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
| at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
| at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
| at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
| at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
| at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
| at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
| at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
| at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
| at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
| at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
| at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
| at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
| at java.lang.Thread.run(Thread.java:595)
| Caused by: java.lang.IllegalArgumentException: Entity not managed
| at org.hibernate.ejb.AbstractEntityManagerImpl.refresh(AbstractEntityManagerImpl.java:260)
| at org.jboss.ejb3.entity.TransactionScopedEntityManager.refresh(TransactionScopedEntityManager.java:193)
| at mil.army.arl.support.integration.earl.ejb.UserSessionFacadeBean.getUserBean(UserSessionFacadeBean.java:72)
| 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.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
| at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
| at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:46)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
| ... 54 more
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4016691#4016691
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4016691
19Â years, 2Â months