Results 1 to 8 of 8
- 12-22-2009, 01:04 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 4
- Rep Power
- 0
problem with Persistence.createEntityManagerFactory
Hi all,
I have an application that runs fine in the netbeans IDE. I have compiled it and run it from the command line (java -jar jarfile.jar), but it dies at Persistence.createEntityManagerFactory(). When I say dies, I mean nothing happens - no exceptions are being thrown that I can see and the method returns null. I have set up a logger that prints to a file and the last thing in the file is "INFO Getting an EntityManagerFactory"
Here is part of the code:
This code is never called when running from a jar (java -jar jarfile.jar):Java Code:myLogger.log(Level.INFO, "Getting an EntityManagerFactory"); EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(myPersistenceUnit, new HashMap<String, String>() { private static final long serialVersionUID = 1L; { put("hibernate.show_sql", "false"); put("hibernate.connection.url", myUrl); put("hibernate.connection.username", myUsername); put("hibernate.connection.password", myPassword); } }); myLogger.log(Level.INFO, "Setting myEntityManager");
Its almost like it cannot find the persistence.xml file (at least that is what I am assuming from my trolling on the web.) One clue may be that it was working fine (from the jar file) until I upgraded my netbeans to 6.8 recently (it only just now occurred to me that this may be the root of the problem - I had made many code changes (none of them relating to the entities) and I assumed that I had broken something. Now I don't know where to start.Java Code:myLogger.log(Level.INFO, "Setting myEntityManager");
Any suggestions would be most welcome
thanks in advance,
Jordan
- 12-22-2009, 11:58 AM #2
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
It is always rocket science when it comes to *.jar packing i hate it myself.
It is strange that you don't get any NoClassDef error.
Few things to check:
- place of src\META-INF\persistence.xml file
- do you have to manuallly add values in
"Class-Path" in your \src\META-INF\MANIFEST.MF file
to all *.jar files needed
-because of possible ClassLoader problems
it is usefull to add all needed *.jar files in your
...jre\lib\ext
folder
- write some System.out.println("...") and run your *.jar in
command prompt to see where is it stopping
- - -
I had problem with using application's *.properties files with *.jar.
You can solve this by editing META-INF\MANIFEST.MF
If *.properties is next to *.jar in your file-system use, do this in META-INF\MANIFEST.MF:
Class-Path: .
(That is Class-Path:blanc.)
it means: look for property file in SAME folder where my app jar file is
If *.properties is in some folder do this in META-INF\MANIFEST.MF:
Class-Path: . folder_name\myproperties.properties
Now, when u use export tools to create app JAR
use this one you just created, dont let wizard do it for u
i hope u will solve this
it's real pain int the *
regards ;)
- 12-22-2009, 01:54 PM #3
Member
- Join Date
- Dec 2009
- Posts
- 4
- Rep Power
- 0
Thanks for the response...
I am actually including a library jar (of mine) that includes the persistence.xml file (so it exists in lib/myEntitlyLib.jar/META-INF of the dist directory.) This saves me from passing the persistence.xml file around for applications that use the entities defined in myEntitlyLib. This used to work fine until recently, but I don't know what I did to break it. I have subsequently tried moving the META-INF directory to the src directory of the top-level jar, but this did not work :-(
I do not normally mess with the Class-Path, although since I started having this problem, I did try adding all of the jar files to it. I get the same error.
I am not familiar with the jre/lib/ext folder. It sounds like this would need to be done for each user of my app? This doesn't sound like a good idea to me, but hey, I'm game for anything at this point!
I have added a logger that prints to a file in /temp. You can see the log commands in my original post - it never gets to the last one.
The app is reading the properties file - because it is logging what it reads. The properties file is in /src of the top-level app.
I will try the Class-Path: . in the manifest, hoping it will resolve the persistence.xml problem. Unfortunately, the app seems to pick up all of the other jars and the properties files.
Here is my manifest from the top-level app (note that netbeans added the Main-Class and Class-Path info):
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 11.0-b15 (Sun Microsystems Inc.)
Main-Class: persysapp.PersysApp
Class-Path: lib/dataLib.jar lib/thompco.jar lib/antlr-2.7.6.jar lib/as
m.jar lib/asm-attrs.jar lib/cglib-2.1.3.jar lib/commons-collections-2
.1.1.jar lib/commons-logging-1.1.jar lib/dom4j-1.6.1.jar lib/ehcache-
1.2.3.jar lib/jdbc2_0-stdext.jar lib/jta.jar lib/hibernate3.jar lib/h
ibernate-tools.jar lib/hibernate-annotations.jar lib/hibernate-common
s-annotations.jar lib/hibernate-entitymanager.jar lib/javassist.jar l
ib/ejb3-persistence.jar lib/mysql-connector-java-5.1.6-bin.jar lib/jc
ommon-1.0.16.jar lib/jfreechart-1.0.13.jar lib/log4j-1.2.15.jar lib/j
calendar-1.3.3.jar
X-COMMENT: Main-Class will be added automatically by build
- 12-22-2009, 04:35 PM #4
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
...I don' t see
myEntitlyLib.jar
in Manifest file
in :
Class-Path: lib/dataLib.jar lib/thompco.jar lib/antlr-2.7.6.jar lib/as
m.jar lib/asm-attrs.jar lib/cglib-2.1.3.jar lib/commons-collections-2
.1.1.jar lib/commons-logging-1.1.jar lib/dom4j-1.6.1.jar lib/ehcache-
1.2.3.jar lib/jdbc2_0-stdext.jar lib/jta.jar lib/hibernate3.jar lib/h
ibernate-tools.jar lib/hibernate-annotations.jar lib/hibernate-common
s-annotations.jar lib/hibernate-entitymanager.jar lib/javassist.jar l
ib/ejb3-persistence.jar lib/mysql-connector-java-5.1.6-bin.jar lib/jc
ommon-1.0.16.jar lib/jfreechart-1.0.13.jar lib/log4j-1.2.15.jar lib/j
calendar-1.3.3.jar
should you add it too?
- 12-22-2009, 05:33 PM #5
Member
- Join Date
- Dec 2009
- Posts
- 4
- Rep Power
- 0
Sorry - I was trying to be generic (before I added the manifest file) - the library file is "dataLib.jar" and it is there.
- 12-22-2009, 11:33 PM #6
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
Something that will not solve your classpath problems but it's good coding practice I think you should easily get used to:
- You made direct impl. of Map interface by writing that HashMap with <K,V> pairs, and put ALL that in SAME line with creation of manager factory.
First be sure that you call this code on app. startup
because creation of manager factory can be long.
Second, values that you put in map can be moved from java code -
move them to either persistance.xml (your 'myPersistenceUnit') or some app. properties file and load them on startup too.
Keep versions of your application - don't let one change ruin all that work
and don't EVER change anything related to app. development (like version of NetBeans etc..) in the middle of project!
hope you will kill your problem soon ;)
- 12-23-2009, 02:42 AM #7
Member
- Join Date
- Dec 2009
- Posts
- 4
- Rep Power
- 0
this has been resolved - turns out that I had removed the mysql jar and added back the mysql library. Ant did not include the library (but it did include the jar.)
- 12-24-2009, 12:38 PM #8
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
Similar Threads
-
Name persistence is not bound in this Context
By tascoa in forum Java ServletReplies: 1Last Post: 12-15-2009, 10:01 PM -
Persistence problem when changing type to java.sql.Time
By Inks in forum JDBCReplies: 0Last Post: 03-08-2009, 01:52 PM -
Container Managed Persistence
By Java Tip in forum Java TipReplies: 0Last Post: 12-27-2007, 10:16 AM -
Hibernate Java Persistence
By JavaBean in forum Java TutorialReplies: 0Last Post: 09-22-2007, 10:02 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks