-
15. Re: Single persistence.xml file with multiple EJB jars
jaikiran Mar 28, 2008 9:04 AM (in response to deanouk)"rruppel" wrote:
let me ask a question:
the persistence.xml has the information about the persistence driver (if it should use Postgresql or Oracle, for example)
but, if I put this information inside persistence.xml, if I change the database, I will have to recompile the jars with the correct persistence.xml
is there a workaround to avoid recompiling the jar?
rruppel,
I believe, you would have a build process where you can handle such things. If you are changing a DB server vendor, then definitely you would have to rebuild the jar (probably not recompile your classes).
P.S: This question is actually not related to what the original poster asked. If you have anymore questions on this please open a new topic in the appropriate forum. That will help in keeping track of the original topic being discussed :)
-
16. Re: Single persistence.xml file with multiple EJB jars
rruppel Mar 28, 2008 9:14 AM (in response to deanouk)
This way here it worked:class Parameters{ void getInterval(); } class Scheduler{ @IgnoreDependency @EJB Executor executor; void schedule(){ executor.schedule(); } } class Executor{ @EJB Parameter parameters; @EJB Scheduler scheduler; @TransactionAttribute(REQUIRES_NEW) void schedule(){ schedule(parameter.getInterval()); } void schedule(long interval){ timerService.createTimer(interval, "myTimer"); } @Timeout execute(Timer timer){ // do lots of things scheduler.schedule(); } } class Servlet{ // not managed by container void contextInitialized(){ Executor executor = lookup(...); executor.schedule(); } }
what I cant understand is:
why it doesnt work if I call the "schedule" method of Executor inside the "execute" method ?
reading again the responses I thought that the answer could be:
You are calling the schedule() method using a raw Java method call
because the "execute" method call the "schedule" method like a raw java method, so it wont see the "REQUIRES_NEW" attribute...
but the example I posted above works, and the "REQUIRES_NEW" attribute has to be above the "schedule" method (I testes changing it to the other schedule method or putting it on both, but only this way at the example works)
and inside the schedule method, I use the datasource1 at "getInterval" and then I call the method schedule
so... its strange this behavior for me....
someone who knows why can explain it please?
another interesting thing is: I was upset with the fact that I would have to use a non-default jar (jboss-annotations-ejb3.jar) which includes the IgnoreDependency annotation, but I tested it without this jar and it worked (strange)...
thanks again for your help... the problem is solved... I just wanna understand now
regards,
RRR -
17. Re: Single persistence.xml file with multiple EJB jars
rruppel Mar 28, 2008 9:16 AM (in response to deanouk)sorry, posted on the wrong topic... you can delete this two posts
thanks for the response -
18. Re: Single persistence.xml file with multiple EJB jars
deanouk Apr 3, 2008 10:55 AM (in response to deanouk)"jaikiran" wrote:
Okay in that case, probably you can place the persistence.xml in the META-INF folder of any one of the ejb jars. Let's assume you placed it in msp1_ejb.jar. The persistence.xml can then contain this:<?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence"> <persistence-unit name="msp-par"> <jta-data-source>java:/@deployeddatabase@</jta-data-source> <jar-file>../</jar-file> <jar-file>../../msp2_ejb.jar</jar-file> <properties> <property name="hibernate.hbm2ddl.auto" value="false"/> <property name="com.intellij.javaee.persistence.datasource" value="Datasource"/> </properties> </persistence-unit> </persistence>
This way both the ejb jar files will be scanned for the entities. I tried this scenario on my local setup of JBoss-4.2.2 and this seems to be working. It picked up the entities that were spread across (and not replicated) the 2 ejb jars. Try it out and see if it works for you.
Sorry its taken so long to reply.
This is exactly what we've tried before - but it still produces the same problem.
i.e. we get:--- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM --- ObjectName: persistence.units:unitName=msp-par State: NOTYETINSTALLED
But without any actual error within the console output. -
19. Re: Single persistence.xml file with multiple EJB jars
jaikiran Apr 3, 2008 11:03 AM (in response to deanouk)Please post the contents of the server.log file. Also, post the contents of the persistence.xml and the structure of your application packaging.
-
20. Re: Single persistence.xml file with multiple EJB jars
deanouk Apr 3, 2008 11:04 AM (in response to deanouk)
<jar-file>../</jar-file>
<jar-file>../../msp2_ejb.jar</jar-file>
By the way - this won't work, not sure how you got it to work, it should be similar to:
<jar-file>../</jar-file>
<jar-file>../msp2_ejb.jar</jar-file> -
21. Re: Single persistence.xml file with multiple EJB jars
deanouk Apr 3, 2008 11:09 AM (in response to deanouk)Persistence.xml:
<?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence"> <persistence-unit name="msp-par"> <jta-data-source>java:/maindatabase</jta-data-source> <jar-file>../ejbcommon.jar</jar-file> <jar-file>../ejbmsp.jar</jar-file> <properties> <property name="hibernate.hbm2ddl.auto" value="false"/> <property name="com.intellij.javaee.persistence.datasource" value="Datasource"/> </properties> </persistence-unit> </persistence>
I can't post the server.log file, this would be huge.
Suffice to say, it simply ends up with the below error, but without any previous error within the stack trace:--- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM --- ObjectName: persistence.units:unitName=msp-par State: NOTYETINSTALLED Depends On Me: jboss.j2ee:ear=earmsp.ear,jar=ejbcommon.jar,name=AuditSe ssion,service=EJB3 jboss.j2ee:ear=earmsp.ear,jar=ejbcommon.jar,name=Company Session,service=EJB3 jboss.j2ee:ear=earmsp.ear,jar=ejbcommon.jar,name=Countri esSession,service=EJB3 jboss.j2ee:ear=earmsp.ear,jar=ejbcommon.jar,name=Dealers Session,service=EJB3 jboss.j2ee:ear=earmsp.ear,jar=ejbcommon.jar,name=UserLoc alesSession,service=EJB3 jboss.j2ee:ear=earmsp.ear,jar=ejbcommon.jar,name=Utility Session,service=EJB3 jboss.j2ee:ear=earmsp.ear,jar=ejbcommon.jar,name=EmailMa nagerSession,service=EJB3 jboss.j2ee:ear=earmsp.ear,jar=ejbcommon.jar,name=Vehicle Session,service=EJB3
The package is laid out as I stated before:
earmsp.ear
----ejbcommon.jar
----ejbmsp.jar -
22. Re: Single persistence.xml file with multiple EJB jars
jaikiran Apr 3, 2008 11:22 AM (in response to deanouk)"DeanoUK" wrote:
<jar-file>../</jar-file>
<jar-file>../../msp2_ejb.jar</jar-file>
By the way - this won't work, not sure how you got it to work, it should be similar to:
<jar-file>../</jar-file>
<jar-file>../msp2_ejb.jar</jar-file>
Yeah, you are right. That was a typo on my part.
The reason why asked for the server.log is because it contains more verbose logs which might help in identifying the issue. The other thing you could do is post the code of AuditSession bean(from ejbcommon.jar) which shows how you inject the PersistenceContext. -
23. Re: Single persistence.xml file with multiple EJB jars
deanouk Apr 3, 2008 11:25 AM (in response to deanouk)Yeah I know it would but I can assure you it doesn't show anything, I'll pm you a link to download it if u like.
AuditSession bean injection:
@PersistenceContext(unitName = "msp-par")
private EntityManager entityManager; -
24. Re: Single persistence.xml file with multiple EJB jars
deanouk Apr 3, 2008 11:27 AM (in response to deanouk)Ok I won't PM you as it won't allow it heh.
Try this:
http://www.allstarconsultants.com/pics/server.log -
25. Re: Single persistence.xml file with multiple EJB jars
jaikiran Apr 3, 2008 11:38 AM (in response to deanouk)"DeanoUK" wrote:
Yeah I know it would but I can assure you it doesn't show anything, I'll pm you a link to download it if u like.
AuditSession bean injection:
@PersistenceContext(unitName = "msp-par")
private EntityManager entityManager;
This looks wrong. This EJB is in ejbcommon.jar where the persistence.xml (persistenceUnit) lies in another jar. So this should look like@PersistenceContext(unitName = "ejbmsp.jar#msp-par") private EntityManager entityManager;
The logs that you uploaded too point the same:[03 Apr 2008 16:26:08] INFO org.jboss.ejb3.JmxKernelAbstraction - installing MBean: jboss.j2ee:ear=eartricsi-1.0.ear,jar=ejbcommon-1.0-SNAPSHOT.jar,name=VehicleSession,service=EJB3 with dependencies:
[03 Apr 2008 16:26:08] INFO org.jboss.ejb3.JmxKernelAbstraction - persistence.units:unitName=msp-par
[03 Apr 2008 16:26:08] INFO org.jboss.ejb3.EJB3Deployer - Deployed: file:/C:/jboss-4.2.2.GA/server/default/tmp/deploy/tmp27049eartricsi-1.0.ear-contents/ejbcommon-1.0-SNAPSHOT.jar
[03 Apr 2008 16:26:08] INFO org.jboss.ejb3.JmxKernelAbstraction - creating wrapper delegate for: org.jboss.ejb3.entity.PersistenceUnitDeployment
[03 Apr 2008 16:26:08] INFO org.jboss.ejb3.JmxKernelAbstraction - installing MBean: persistence.units:ear=eartricsi-1.0.ear,jar=ejbtricsi-1.0-SNAPSHOT.jar,unitName=msp-par with dependencies:
[03 Apr 2008 16:26:08] INFO org.jboss.ejb3.JmxKernelAbstraction - jboss.jca:name=maindatabase,service=DataSourceBinding
[03 Apr 2008 16:26:08] INFO org.jboss.ejb3.entity.PersistenceUnitDeployment - Starting persistence unit persistence.units:ear=eartricsi-1.0.ear,jar=ejbtricsi-1.0-SNAPSHOT.jar,unitName=msp-par
As can be seen here, the persistence unit msp-par has been deployed successfully. The reason why your beans are failing is because without the jar file name prefix, the persistence unit will be searched for within the ejbcommon.jar. -
26. Re: Single persistence.xml file with multiple EJB jars
jaikiran Apr 3, 2008 11:42 AM (in response to deanouk)And while trying this with jarname#unitName, please do have a look at http://www.jboss.com/index.html?module=bb&op=viewtopic&t=132775. You will probably end up, injecting it like this:
//Prefix 3 random characters to the unitName @PersistenceContext(unitName = "XXXejbmsp.jar#msp-par") private EntityManager entityManager;
-
27. Re: Single persistence.xml file with multiple EJB jars
enazareno May 8, 2008 6:24 AM (in response to deanouk)Hi DeanoUK,
I have the same problem as yours and I've looked for 2 days with no concrete answer. My structure is quite like yours - I have several ejb jars (without the persistence.xml ) registered in an ear and I have an extra mypu.jar which does not contain the entity classes - only the persistence.xml. Why is this as such? I have a large project with several ejb modules and some are re-usable entities which must be packaged separately. I must share a persistence.xml because entities from one module depend on the reusable classes - I cannot have several persistence.xml in each entity's jars. I must register the ejb jars under the ear because there is no other way for it to be accessed remotely this way - "earname/MyService/remote". This is fine and it works. The problem is my entities are inside the entity jars and I cannot scan it using the jar-file syntax as pointed :<jar-file>../myjar.jar</jar-file>
Why? Because this is only true if the entity classes are under mypu.jar but - it is outside this jar. If you omit the "../" the jar files must be located in the bin directory. I have several solutions to workaround this:
1. In the jar-file, really specify the absolute path. i.e., /jbossroot/server/default/deploy/myear.ear/thejar.jar. This is not a great solution because it is not portable. Ideally it should be relative path. Unless we can specify a special url handler that points to the ear like a "resourceloc://myear.ear" for example, this might be better, or if the persistence.xml can support property substitution, this can work too like ${mypath}/jarfile.jar.
2. Do not use jar-file, use explicit declaration of classes. I have not tried it but I think this should work. The only problem is - I have several entities and it might be hell to register it one by one. Also, if I refactor, it might be too unwieldy.
3. Have a separate package for entities and stateless session beans(SSB). The entities will be under mypu.jar, while the stateless session beans will be reigstered as ejb module. On second thought, how do I access the entities from the SSB? I have not tried this path.
4. Only mypu.jar will be registed in the ear, and all other jars under it referenced with jar-file in the persistence.xml. It deploys cleanly but the problem, like I mentioned, I cannot access the statless session beans as an ear.
5. All classes are exploded and packaged only in one jar. This is my current setup and the reason why I am hassling myself today for a better solution.
I hope there is a better way of doing this.
Cheers,
Elmo
-
28. Re: Single persistence.xml file with multiple EJB jars
gcshields May 23, 2008 7:28 PM (in response to deanouk)Is this a bug?
If I have a jar file that has my entities in it - myApp.jar with the persistence.xml file in it and I have a jar with common entities named myCommonStuff.jar in the same directory.
If I put the absolute path in the persistence.xml file -
...
<jar-file>/absolute/path/to/my/jar/myCommonStuff.jar</jar-file>
...
It picks it up fine.
If I try
<jar-file>../myCommonStuff.jar</jar-file>
jboss looks for it inside the myApp.jar file.
If I try
<jar-file>../../myCommonStuff.jar</jar-file>
jboss looks for it inside the myApp.jar file, but now it looks for a file called 'yCommonStuff.jar'! (removes first character in filename instead of moving back a directory).
I am running 4.2.2.GA
thanks,
g -
29. Re: Single persistence.xml file with multiple EJB jars
jaikiran May 23, 2008 11:55 PM (in response to deanouk)"gcshields" wrote:
If I try
<jar-file>../myCommonStuff.jar</jar-file>
jboss looks for it inside the myApp.jar file.
If I try
<jar-file>../../myCommonStuff.jar</jar-file>
jboss looks for it inside the myApp.jar file, but now it looks for a file called 'yCommonStuff.jar'! (removes first character in filename instead of moving back a directory).
I am running 4.2.2.GA
By any chance, is your jar file in exploded format (in the form of a directory) instead of a zipped archive? If yes, then the issue might be because of this http://jira.jboss.org/jira/browse/EJBTHREE-1254