EntityFactoryManager(emf) is successfully received but error at emf.createEntityManager
Please see my code of fragment from my project.
public class Main { final private static Properties EMAIL_PROPS; final private static String EMAIL_FROM; static { EntityManagerFactory emf = javax.persistence.Persistence.createEntityManagerFactory("tmpCLMSPU"); // System.out.println("EMF: "+emf); //OUTPUT: EMF: org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl@ffa7e1 EntityManager emTemp = emf.createEntityManager(); TypedQuery<EmailSettings> emailSettings = emTemp.createNamedQuery("EmailSettings.findByName", EmailSettings.class).setMaxResults(1); EmailSettings smtp, port, from; smtp = emailSettings.setParameter("name", "SMTP").getSingleResult(); port = emailSettings.setParameter("name", "Port").getSingleResult(); from = emailSettings.setParameter("name", "EMAILFROM").getSingleResult(); // Get system properties EMAIL_PROPS = System.getProperties(); // Setup mail server EMAIL_PROPS.put("mail.smtp.host", smtp.getValue()); EMAIL_PROPS.put("mail.smtp.port", port.getValue()); EMAIL_FROM = from.getValue(); emTemp.close(); emf.close(); } //Empty Constructor public void Main() { } public static void main(String[] args) { new Main(); }
My project was was running successfully but All of sudden, it is showing following error:-
java.lang.ExceptionInInitializerError Caused by: javax.persistence.PersistenceException: java.lang.NullPointerException at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:766)
I am using Netbeans JAVA IDE for my project. I am very frustrated after lot of tries at my end to solve this problem. I tried following but FAILED:-
I ran my program again after each of following step but still Error is showing.
I check my database services. It is successfully connected. Connection is OK.
Restart Database server (SQL Server) services on Server.
Delete NetBeans configuration's Users directories.
Restart Server & Also, My client Computer.
Create a separate project & copy my original sources into it. I did the all configuration part of my project again i.e. adding Libraries, Setup Database Connections & Persistence Unit again.
However same database setup is working fine for other project. I found same problem on Internet:-
http://www.dreamincode.net/forums/topic/285379-javaxpersistencepersistenceexception-javalangnullpointerexception/
No proper solution is given on above link Because it is not NullPointerException. EntityFactoryMnager is retrieved successfully. Please see the attachments:-
EmailSettings.java : an Entity
Main.java : Main program to run
Persistence.xml.txt : File containing persistence information
Stacktrace.txt : complete stack trace after error is showing.
Have anyone idea to solve this problem?
Thanks In Advance,
GAJESH