开发者

how inject a EntityManager between ear

I'm using JBoss 4.2.3 and I deployed two ears called triad-1.0.ear and reportservices-1.0开发者_StackOverflow中文版.ear, the thing is that I want to use the entity manager of the project triad in the project reportservices. This is the architecture JBoss follows:

triad-1.0.ear:
             triad-core-1.0.jar:
                                META-INF:
                                         MANIFEST.MF
                                         components.xml
                                         ejb-jar.xml
                                         jboss.xml 
                                         persistence.xml    
reportservices-1.0.ear:
              reportservices-core-1.0.jar:
                                          META-INF:
                                                  MANIFEST.MF
                                                  components.xml
                                                  ejb-jar.xml
                                                  jboss.xml
                                                  persistence.xml

this is my attempt to make the entitymanager global between ear in the persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!--
     Attention: Generated code! Do not modify by hand!
     Generated by: persistence.xml.vsl in andromda-ejb3-cartridge.
-->
<persistence 
    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"
    version="1.0">
    <persistence-unit name="triad">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:/jdbc/triad</jta-data-source>
        <properties>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/>
            <property name="jboss.entity.manager.jndi.name" value="java:/triadFactory"/>
            <property name="jboss.entity.manager.factory.jndi.name" value="java:/triadFactory"/>
        </properties>
    </persistence-unit>
</persistence>


I'm sorry but the question doesn't make much sense in my opinion (I don't even get what you mean by "make public the persistence.xml"). Just in case, it is possible:

  • to use the same datasource in several persistence units.
  • to (re)use a persistence unit in several applications (provided the packaging make it possible).

My suggestion would be to explain what you would like to do in plain english (forget the technical details for now).


i finally solved mi problem with the injection, you need to set this properties in the persistence.xml and check in jboss jmx console, in the option of jdni view if the injection was correct the properties here's an example of the persistence.xml

<persistence  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" version="1.0">
    <persistence-unit name="example">  
        <provider>org.hibernate.ejb.HibernatePersistence</provider>  
        <jta-data-source>java:/jdbc/example</jta-data-source>  
        <properties>  
            <property name="hibernate.hbm2ddl.auto" value="update"/>  
            <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/>  
            <property name="jboss.entity.manager.jndi.name" value="java:/example"/>  
            <property name="jboss.entity.manager.factory.jndi.name" value="java:/example"/>  
        </properties>  
    </persistence-unit>  
</persistence>`

the properties that allowing the injection are "jboss.entity.manager.jndi.name" and "jboss.entity.manager.factory.jndi.name"

notes the data have the same name that the data source but called by his jdni name sets in the xml of the datasource project.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜