JPA and JSF - Problem persisting object

Hi all.
I'm having some trouble with JPA, persisting an object to a MySQL table.
Let's say I have a simple bean, Message:
package my.package
import java.io.Serializable;
import javax.persistence.Id;
import javax.persistence.Entity;
import javax.persistence.Column;
import javax.persistence.Table;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
@Entity
@Table(name="messages")
public class Message implements Serializable {
     @Id
     @GeneratedValue(strategy=GenerationType.AUTO)
     private int id;
     @Column(name="message_text")
     private String message;
     @Column(name="message_author")
     private String author;
     public String getMessage() {
          return this.message;
     public void setMessage(String message) {
          this.message = message;
     public String getAuthor() {
          return this.author;
     public void setAuthor(String author) {
          this.author = author;
}And a controller for this Message bean:
package my.package;
import javax.annotation.Resource;
import javax.persistence.Query;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import javax.transaction.UserTransaction;
public class MessageController {
     @PersistenceUnit(unitName="em1")
     private EntityManagerFactory emf;
     @Resource
     private UserTransaction utx;
     private Message message;
     public Message getMessage() {
          return this.message;
     public void setMessage(Message message) {
          this.message = message;
     public String save() {
          EntityManager em = null;
          String returnValue = "";
          try {
               em = this.emf.createEntityManager();
               utx.begin();
               em.persist(this.message);
               utx.commit();
               returnValue = "success";
          } catch(Exception e) {
               e.printStackTrace();
               returnValue = "failure";
          return returnValue;
}Relevant code from the faces-config.xml:
<managed-bean>
     <managed-bean-name>MessageController</managed-bean-name>
     <managed-bean-class>my.package.MessageController</managed-bean-class>
     <managed-bean-scope>request</managed-bean-scope>
     <managed-property>
          <property-name>message</property-name>
          <property-class>my.package.Message</property-class>
          <value>#{Message}</value>
     </managed-property>
</managed-bean>
<managed-bean>
     <managed-bean-name>Message</managed-bean-name>
     <managed-bean-class>my.package.Message</managed-bean-class>
     <managed-bean-scope>request</managed-bean-scope>
</managed-bean>This is my simple persistence.xml:
<?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 ="em1">
         <jta-data-source>jdbc/__glfish</jta-data-source>
    </persistence-unit>
</persistence>The __glfish resource is all set up via Glassfish to point to my MySQL server, via a MySQLPool.
Can anyone see what I'm doing wrong? The Message doesn't get added to the table in my database, and I get a NullPointerException in the method MessageController.save() on the property MessageController.message - which I have specified in the faces-config.xml. Shouldn't that be enough? What have I missed?

Ok, I have (re-)located the problem. It's not my Message property which gets a NullPointerException - it seems like the problem is with my EntityManagerFactory instance. The PersistenceUnit don't get assigned, even though I declare it in my persistence.xml file.
Maybe it is something wrong with my file structure?
The .war file have this structure:
- WEB-INF
     - classes
          - my
               - package
                    Message.class
                    MessageController.class
     - lib
          [external jars goes here]
          - META-INF
               persistence.xml
     faces-config.xml
     web.xml
[*.jsp/*.xhtml goes here]Can anyone see what's wrong?

Similar Messages

  • How do I fix my ipod classic that says very low batter after I have charged it and the problem persists?

    I have an Ipod video 30g that says Please wait very low battery. I charged it for about a day and the problem persists. I've tried using some solutions on the internet and none of them worked including: holding the menu and select, holding select and play to put it in disk mode with no avail. Is there anyone who can help me!!!

    Have you read this post written by another forum member?
    The Sad iPod icon.
    However, as your iPod was purchased on Boxing Day, why not get it serviced under the warranty?
    You can arrange online service here.
    Service request.
    Or if an Apple store is near you, take it there and have them check your iPod.
    You can make an appointment by using this link.
    Genius Bar Appointments.

  • Can't open iTunes, it said it has failed to start because MSVCR80.dll was not found, and I re-installed application many times and still problem persist, how do I solve this?

    can't open iTunes, it said it has failed to start because MSVCR80.dll was not found, and I re-installed application many times and still problem persist, how do I solve this?

    Try the following user tip:
    Troubleshooting issues with iTunes for Windows updates

  • A few selection of websites after fully loading become blank and start an infinite loop of loading. I reinstalled firefox once already and the problem persists. What can I do?

    A few selection of websites after fully loading become blank and start an infinite loop of loading. I reinstalled firefox once already and the problem persists. What can I do?

    Sorry I do not know what the problem may be. <br />
    If no-one comes up with better ideas of what causes this then my questions and suggestions:
    What do you mean by an infinite loop ? <br />
    The page loads and then goes blank. What exactly happens next, does the page fully load and fully display again before going blank, and repeat this cycle endlessly in the same tab.
    You do say the problem persisted in safe-mode and you had looked at the basic troubleshooting article. Buy that you can stop the problem by disabling javascript.
    * did you disable all plugins - and did you still get the problem then ?
    As you mention disabling javascript stops the problem, have you tried with<br /> Java script enabled but
    * block popups ON
    * load images automatically OFF
    * advanced options - ALL OFF<br /> What happens do you get the problem then or not.
    While on this firefox site if I look at the error console Ctrl+Sift+J or Tools -> Error console If I clear the console content and reload the webpage the error console shows only a couple of messages. YouTube home page give a lot of yellow triangle warnings about 200, but no red warnings, do you get red warnings.
    You could also try on the problem sites eg YouTube changing the permissions with tools -> Page Info | Permissions
    Did you try the Basic Troubeshooting suggestion of making a new profile. (Heeding the warning not to delete settings, otherwise you loose all bookmarks etc) did that help ?

  • Please help: How to fix error message: Connection error. Try again. Check configuration and if problem persists contact the administrator.

    Please help on how to fix this error message when I'm trying to connect on my VPN
    Connection error. Try again. Check configuration and if problem persists contact the administrator.

    Thanks for the info.

  • I cannot connect to the login page of my banking websites for Firefox but can from IE also firefox does not close when I shut it down I have just done a clean instal of windowsws7 and teh problem persists on reinstall of FF3.6.13

    I can connect with my banking websites but the login page will not come up. This is a recent occurrence and I have done virus scans and have also recently done a clean instal of Windows 7. The problem persists. I can connect to any other website with no problems. When I close FF it appears to close and Task manager shows as not running but it will not reopen. If I attempt to uninstall I am told that FF is running and needs to be closed. I have to reboot to get to close and be able to reopen.
    I can connect to the bank sites with IE. However I really don't like IE.
    I am using Win7 Professional on a Sony notebook VGN SZ55

    I don't have an answer, but I experienced the same problems trying to set up an airport express to route traffic to my stereo.
    Apple Extreme router, iMac and laptop all worked just fine for months, upon installing Airport Express (step by step, according to instructions), all **** broke loose. Airport Utility was unable to see my Airport Extreme router, after hours of rebooting computer, cable modem, router, and finally a hard reset of the Airport Extreme router, it is finally recognized by Airport Utility again.
    Recreated network, iMac connects to the internet just fine, laptop (Macbook Air) connects to the network just fine, but will not connect to the internet. Network diagnostics does not help, it gets to the "do you have a router? If so, reboot" stage, and never seems to see the router.
    Any suggestions?

  • My Atv2 is  very slow movies and shows take forever to load it plays for a few minutes then pauses again. I thought if was a problem with my wireless router but I replaced it with a new airport extreme and the problem persists. Air play is just as slow.

    My Atv2 is very slow with both AirPlay and rented and purchased content I spoke to apple rep and tried the things he suggested but the problem persists. Now it requires more lead time then the lenght of material being viewed. I haves broadband internet connection and airport extreme router so I don't think this should be a problem. Lately every time the unit goes to the screen saver an error message come up saying there was an error while loading content please try again later and you have to all over again. It is extremely frustrating. Any suggestions? What speed of transfer should I expect using AirPlay ?

    I'm having the same issue.  Ay fixes?  Bought ATV today, music streams but videos don't and mirroring doesn't work either.  Start mirror and severe lag then just drops.  Been trying for couple hours. About ready to return it.

  • JPA & visual JSF problem

    Hello, everybody :),
    I'm new to Java Web Development, and I'm in big trouble, :) and I'm on the edge of despair. I'll appreciate any help.
    Here is the problem - I've been trying for hours to do something like [ this|http://www.netbeans.org/kb/60/web/web-jpa.html] tutorial example but it is not working for me!
    I've changed it a bit - I'm using MySQL, I created a few Entity classes from the database, I created controllers from them (right click -> JPA controller Classes from Entity Class). I've bounded the table (from the example) as it was said and then I tried to run the application - it started but the table was emplty and in it was written that "No items found". I 100% sure that the table in the database is not empty and there are no error messages.
    I tried to debug the application then I saw that when I go to the updateUsers() mehtod in the entity class controller and I try to get the EntityManager something crashes and I go straight to the calling SessionBean1 with NULL as a user list - can you help me?
    Something more, when I create new Web project and I create the Entity classes from the database - the one that I'm having problem with for the Persistence example, and I create JSP pages for the entity classes - (you know just right click + .....) and the CRUD application is working just fine - I don't understand what is wrong with my trial to use the Java Persistence API Within a Visual Web JSF Application?
    Thanks in advance!
    P.S. Sorry for posting this topic again - I thing is the better place to get answer.
    Edited by: GGeorgieva on Jan 1, 2009 3:40 PM

    You're right again - can you help me with finding the reason for this, I'll paste some of the server log:
    It is the database? I guess? But how could it be - I've been working with that very DB from another Web Java Application?
    So is there a RIGHT way to connect to MySQL DataBase from a JavaSE project, which we have connected to a Web Java Application?
    javax.persistence.PersistenceException: No Persistence provider for EntityManager named aPU: Provider named oracle.toplink.essentials.PersistenceProvider threw unexpected exception at create EntityManagerFactory:                     
    oracle.toplink.essentials.exceptions.PersistenceUnitLoadingException                    
    Local Exception Stack:                     
    Exception [TOPLINK-30005] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.PersistenceUnitLoadingException                    
    Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: WebappClassLoader                    
    delegate: true                    
    repositories:                    
    /WEB-INF/classes/                    
    ----------> Parent Classloader:                    
    EJBClassLoader :                     
    urlSet = []                    
    doneCalled = false                     
    Parent -> java.net.URLClassLoader@f66abc                                        
    Internal Exception: javax.persistence.PersistenceException: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.EntityManagerSetupException                    
    Exception Description: predeploy for PersistenceUnit [aPU] failed.                    
    Internal Exception: Exception [TOPLINK-7250] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.ValidationException                    
    Exception Description: [class classes.Person] uses a non-entity [class classes.Phone] as target entity in the relationship attribute [private java.util.Collection classes.Person.phoneCollection].                    
    "     at oracle.toplink.essentials.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:143)"                    
    "     at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createEntityManagerFactory(EntityManagerFactoryProvider.java:169)"                    
    "     at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:110)"                    
    Caused by: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.EntityManagerSetupException                    
    Exception Description: predeploy for PersistenceUnit [aPU] failed.                    
    Internal Exception: Exception [TOPLINK-7250] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.ValidationException                    
    Exception Description: [class classes.Person] uses a non-entity [class classes.Phone] as target entity in the relationship attribute [private java.util.Collection classes.Person.phoneCollection].                    
    "     at oracle.toplink.essentials.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:228)"                    
    "     ... 87 more"                    
    Caused by: Exception [TOPLINK-7250] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.ValidationException                    
    Exception Description: [class classes.Person] uses a non-entity [class classes.Phone] as target entity in the relationship attribute [private java.util.Collection classes.Person.phoneCollection].                    
    "     at oracle.toplink.essentials.exceptions.ValidationException.nonEntityTargetInRelationship(ValidationException.java:1140)"                    
    "     at oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataValidator.throwNonEntityTargetInRelationship(MetadataValidator.java:321)"                         
    "     ... 86 more"                    
    The following providers:                    
    oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider                    
    Returned null to createEntityManagerFactory.                    
    "     at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:154)"                    
    "     at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)"                    
    "     at cntrllrs.PersonJpaController.<init>(PersonJpaController.java:33)"

  • JAVASCRIPT AND JSF PROBLEM REFRESHING PAGE PROBLEM

    Hello everyone, I am currently using visual JSF and javascript to to disable a fileupload component when a radio button is clicked. I don't have any problems getting it to work if I need to disable a button, a textfield or other visual JSF components. For some reason, i can't disable the fileupload component and I get this error when the JAVASCRIPT is called:
    Error: document.getElementById("form1:fileUpload1").refresh is not a function
    Source File: http://localhost:8080/TestSingleEvent/theme/com/sun/webui/jsf/suntheme4_2-080320/javascript/webui.js
    Line: 22
    My javascript code is the following:
    document.getElementById("form1:fileUpload1").refresh("form1:radioButton1");return false;
    I would appreciate some help here. Why is it that when I replace the fileUpload with i.e a textfield i don't get errors..
    Is it something to do with the webui.js ?
    Many thanks.

    There is no such thing as refresh() in the [DOM element|http://developer.mozilla.org/en/DOM/element]. How did you come to this? Did you a wild guess in the around without reading the docs? Don't do that.
    What exactly do you want to achieve? Reset its value? Then set the 'value' property to null. Disable the element? Then set the 'disabled' property to true.
    I've been helpful enough with this offtopic question. If you still stucks, please continue at a Javascript oriented forum. There's one at under each webdeveloper.com.

  • My updates are failing.  Adobe application manager may be damaged.  I have downloaded and installed a new copy and the problem persists.   Please help.

    I am trying to update Photoshop CS6 in order to read my camera's RAW files.  It is a camera that is supported by Adobe Photoshop CS6.  However, when I try to get the Adobe Application Manager to update the software, it fails to do so.  (The spinning wheel tells me it is checking for updates and then quits, saying that "Update Failed - Updates could not be applied.  Adobe Application Manager may be damaged.  Download and install a new copy of Adobe Application Manager.")
    I have tried to reinstall the Adobe Application Manager 8.0, which gives me the following error message "We've encountered the following issues.  Installer failed to initialize.  Please download Adobe Support Advisor to detect the problem."  However, when I go to the link provided to download the Adobe Support Advisor, this piece of software NO LONGER EXISTS. "
    The Adobe Support Advisor has been discontinued
    The Adobe Support Advisor tool was used to analyze installer log and system information associated with installation errors. The tool has been replaced with improved installation support mechanisms. Please visit Adobe Support section for Knowledge base articles around Installation."
    So, I have gone to the forums and took the recommended step to update my software manually - getting the update Photoshop_CS6_13_0_6upd-2.dmg.  However, this update also fails stating that my Adobe Application Manager may be damages.  Download and install a new copy of Adobe Application Manager.  Which puts me right back where I started.  
    I have also taken the step of completely reinstalling Photoshop CS6.  This did not solve the problems outlined above.  
    Please help!

    reset your preferences:
    dreamweaver:  http://helpx.adobe.com/dreamweaver/kb/restore-preferences-dreamweaver-cs4-cs5.html
    flash:  http://helpx.adobe.com/flash/kb/re-create-preferences-flash-professional.html
    indesign:  https://forums.adobe.com/thread/526990
    lightroom:  http://www.lightroomforums.net/showthread.php?14226-Resetting-%28or-Trashing-%29-the-Light room-Preferences-file
    photoshop:  https://forums.adobe.com/thread/375776
    if that fails, uninstall ps, clean (Use the CC Cleaner Tool to solve installation problems | CC, CS3-CS6) and reinstall.  then use the manual updates.

  • My phone app freezes and message app crashes. I tried restarting multiple times and the problem persists. Everytime i go to the phone app and press on a contact to call it just freezes up and does nothing. Does anyone know how to fix this problem?

    My phone app freezes and when i press on contact either it freezes or does nothing. Anyone know how to fix this problem? Also messaging app crashes. ANOTHER NEW PROBLEM: I can't receive calls either.

    Try to reset the phone by holding the sleep and home button for about 10sec, until the Apple logo comes back again. You will not lose any data by resetting, but it can cure some glitches.
    If this does not help, setting it up as new device would be the next step:
    How to erase your iOS device and then set it up as a new device or restore it from backups

  • Jstl and jsf problem

    i'm programming with jsf and have to use jstl tag
    i cant access "var" in jsf tags
    how can i use # with forEach items attribute ?
    or how can i use $ with jsf tags ?
    <c:forEach  items"${x}" var="x">
    <h:outputText value="${x.documentNo}" />
    </c:forEach>

    soso_xuc wrote:
    i'm programming with jsf and have to use jstl tag
    i cant access "var" in jsf tags
    how can i use # with forEach items attribute ?
    or how can i use $ with jsf tags ?
    <c:forEach  items"${x}" var="x">
    <h:outputText value="${x.documentNo}" />
    </c:forEach>
    If you're using at least JSF 1.2 with at least JSTL 1.2, you can just use unified EL (the "JSF EL") in c:forEach.
    <c:forEach items="#{x}" var="x"><h:outputText value="#{x.p}"/></c:forEach>That said, using c:forEach in JSF is not recommended (as almost every JSTL tag/taglibs, only the Functions taglib is useful). Rather go for an JSF UIData component which does not output anything, such as Tomahawk t:dataList and RichFaces' a4j:repeat. If you're using Facelets instead of JSP, you could also use ui:repeat.

  • Mouse not active on top 1/4 of page. Won't give a pointing finger there. Can't log out or use any of the tabs at the top of a page. Internet Explorer does not do this, but we like your browser better. We just downloaded an update and the problem persists.

    On this page we cannot log out or use the search box or pick desktop or mobile. Once we get down to the "firefox help/forum" level the pointing finger comes up and we can activate a mouse click there. Above that nothing.

    The Yahoo! Toolbar extension and the Babylon extension have been reported to cause this issue. Disable or uninstall those add-ons.
    * https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes

  • Premiere Elements 12 Project Assets panel will not drop. Reloaded software and problem persists.

    My project assets panel went kaflooey. I've seen this question raised in other Premiere 12 forums, but never fixed. I removed and reloaded the software and the problem persists.

    spocksclownshoes
    What computer operating system is your Premiere Elements 12 running? I will assume Windows 7, 8, or 8.1 64 bit for now.
    First try...deleting the Adobe Premiere Elements Prefs.
    Local Disk C
    Users
    Owner
    AppData
    Roaming
    Adobe
    Premiere Elements
    12.0
    and in the 12.0 Folder is the Adobe Premiere Elements Prefs file that you delete. If that does not work, then delete the whole 12.0 Folder in which
    the Adobe Premiere Elements Prefs file exists. Be sure to be working with Folder Option Show Hidden Files, Folders, and Drives enabled so that you can
    see the complete path cited.
    If no success with the above, then...
    With video or still in Documents and Premiere Elements opened to the Expert workspace, right click the computer taskbar and select Cascade Windows.
    Then drag video or still from Documents into the Premiere Elements Expert workspace Timeline.
    Does Project Assets pop open?
    Please review and consider, and then we will decide what next based on the details in your reply.
    Thank you.
    ATR

  • Z1 bluetooth and network problem after updating to 1.136

    Hi,
    Last week I updated my phone via PC companion when it notified me a new system update was available. The update took me from Android 4.2.2 to 4.3, and the biuld number is now 14.2.A.1.136.
    I use my phone with a SmartWatch 2 all the time, and a SBH20 bluetooth headset in my car. Before the update everything worked fine, but now I have issues with bluetooth connectivity. My SmartWatch 2 randomly disconnects and reconnects to the phone, and so does the headset. In the watch, specifically the Whatsapp notification app by LIS software stopped getting notifications most of the time, although every once in a while it does. The SBH20 also randomly disconnects and sometimes it takes minutes to reconnect by itself. I already unpaired and paired again both devices, even reset the SmartWatch, and the problem persists.
    But the most recurrent issue is that the phone repeatedly notifies me to "Sign in to network"... and has problems connecting to the 4G and even to wi-fi networks, meaning that sometimes I don't get any data at all for who knows how long, because it happens randomly.
    One thing that seems to me is that every time i lose my bluetooth connections it's because (or at the same time) of whatever happens that triggers the "Sign in to network" notification.
    I was really happy of having purchased the whole package of phone, watch and headset, please help me with this.
    Leonardo

    This is the responses I go from Sony "Customer DON'T Care....." regarding bluetooth issues - 
    "We can advise Sony Xperia do not test our products with other manufacturer’s devices and so we can not confirm the two devices are compatible.
    As the handset has been updated this does indicate it is running different software which means the Bluetooth will have also been updated. Sadly, as Sony Xperia does not test our products with third party Bluetooth devices we will not have been able to foresee the change with your specific device.
    We could only suggest that you contact the manufacturer of the device for any further assistance as there is nothing further we could advise.
    We do apologise for any inconvenience this may have caused.
    It is not that the software does not work it is the fact that we have updated the bluetooth drivers withing the update you have which no longer makes the bluetooth compatable with your car kit, if you ahve not contacted the car manufacturer already then I would suggest contacting them and seeing if there are any updates needed to the car kit."
    Mmmmmm... so it seems that they DO NOT test any O/S upgrades against anything.....
    It seems strange that both Samsung(S3 running 4.3)  and HTC M* (running 4.4.2) both work perfectly with my car audio system and the "developers" at Sony cant... either that or they just do not care... The smart money is on the latter... My z1 is THE WORST PHONE THAT I HAVE EVER HAD THE MISFORTUNE OF OWNING....

Maybe you are looking for

  • Transfer of Data from Form to Excel

    I would like the data shown on the forms to be transferred to excel sheet. This is because the users would like to do certain manipultaion on the data. How is this possible. Kindly let me know Thanks in advance Gaurav

  • Where can I find deleted files in Bridge CC?

    I have been opening files from an SD card in bridge CC today. By mistake I pressed the delete key.... The trashcan on my computer does not display the file. As I know the name and the file type, I did a general search on my (windows 8) PC without any

  • Export raw video

    How do I upload video directly to a server without my Mac converting files to QuickTime format?

  • Adobe Flash Timeline problem

    When I open a flash file, I see all my layers, but Flash doesn't show the frames on the layers. ( Screenshot) Can someone tell me how to fix this? Regards, Jeroen

  • Sine function voltage input

    Hi there, I'm a newbie in using Labview with the 6487 picoammeter. I'm trying to characterize the electrical properties of a type of ionic conductor, silver sulfide, and need to use Labview and 6487 to do it. The task I'm working on is that I want to