Separate project trouble [message #665658] |
Fri, 15 April 2011 08:03  |
Eclipse User |
|
|
|
So in short:
Latest eclipse 3.6
Glassfish 3.1 integrated
EclipseLink
All gotten from within the eclipse and latest versions.
Now, I can get JPA to work in a single project,but when I put the persistence in one project and EJB in another I cannot ever make the EntityManager to appear.
Also there is a plethora of weird InvalidState errors and debugger desynchs that can be solved only by restarting and redeploying.
But to focus, the thing is set up as such:
* JPA project with classes and persistence.xml
* EJB project that does stuff
* JSF project
* EAR project including all
Whenever I get to a point that would invoke the EntityManager I see that it is null.
I use
@Inject
@UserDatabase
EntityManager em;
in EJB
and I have this
@Singleton
public class UserDatabaseEntityManager {
@Produces
@UserDatabase
@PersistenceContext(unitName="name")
private EntityManager em;
}
somewhere. I have tried putting the latter in both projects and it does not work in either, no EntityManager ever comes from the server. I guess I am doing something wrong here but I saw a few sources claiming this should be enough, obviously aint for my setup.
I guess this example was wrong or something but anyway, what would be the proper way of doing it then? I'd like to modularize stuff and take advantage of the jpa /ejb facilities.
Also currently I have in persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="name" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>...class here </class>
<properties>
<property name="javax.persistence.jdbc.url" value="url here"/>
<property name="javax.persistence.jdbc.user" value="user"/>
<property name="javax.persistence.jdbc.password" value="pass"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
</properties>
</persistence-unit>
</persistence>
Also tried to use the JTA facility here and define jdbc connection and pool on the server and that way doesn't work at all for me not even in a simple project.
Is there anything I am obviously doing wrong? It is apparent I am starting a lot of new stuff here at once, but heck at least this should have been simple no? Its problematic when you don't even have a tutorial that could help me... hence any help much appreciated.
|
|
|
|
Re: Separate project trouble [message #666100 is a reply to message #665658] |
Tue, 19 April 2011 03:06  |
Eclipse User |
|
|
|
I got this weird error
javax.servlet.ServletException: Exception [EclipseLink-4021] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Unable to acquire a connection from driver [null], user [null] and URL [null]. Verify that you have set the expected driver class and URL. Check your login, persistence.xml or sessions.xml resource. The jdbc.driver property should be set to a class that is compatible with your database platform
but then I somehow managed to punch through in a test project no.2... I guess its all about the settings. And the finese must play a large part too, so its not really all that friendly for someone trying for the first time.
I can get something to work, add a few things and I have to retrace and retry a few times to get even the most basic programs through.
So I will take your advice:
1) Always JTA, I guess I botched at jumping to more advanced ways of managing persistence context, gone back to the roots and it works now.
2) Still have trouble here though, for now I have persistence.xml in ejb bean, can I just put it into the jpa utility jar? It was my original intention to do this, but do I have to export the jar and include it? I was thinking of just referencing the jpa project under java build path of the ejb project. Om, seems to work now too, at least in my test project. And I don't have a clue how since I've been doing much the same thing for a while now. I guess I will have to figure this out.
3) Ye, this solved it for me. Not that my project was much more complex, but I guess @PersistenceContext is simpler than @Injecting produced EntityManager, though that should still works simply from what I gather...
Thanks for now, hope I can start with this finally.
edit: Om, I still cannot debug the main project. If I set a breakpoint in EJB it gets hit but I cannot step by step the execution after that... any clues regarding this?
edit2: So, any ideas why do I randomly get that null null errors? Then I just refresh a few times and a few of them it works and a few I get nulls... (nulls to datasource? what?)
[Updated on: Wed, 20 April 2011 04:41] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03568 seconds