JPA EJB generic DAO

I am using Jdeveloper 11g R (11.1.2.3) & weblogic 10 G
In my pages I use JSF & Facelet
Hi All
  In a new project I am going to use JPA / EJB session beans and ADF Faces
  Also I am going to use similar pattern described in below link for a GenericDAO
  and inject instances of Generic EJB into my business EJBs
    http://www.adam-bien.com/roller/abien/entry/generic_crud_service_aka_dao
    https://blogs.oracle.com/theaquarium/entry/generic_jpa_dao_repository_implementation
  In second link some people mentioned this way is old and over simplified
  Any body have any comment / ideas or similar cases
  I don't want use any external open source libraries
Thanks
Mohsen

I've read that article several months ago and didn't get a chance to try it out. However, I did work with Hibernate quite a bit.
I believe the author would have us replace this:
public update(Person person){
with this:
public void update(T o) {
In the first function, its obvious that I'm updating a record in the Person table.
In the second function, I need to have a list of all the possible table names (such as 'Person') to know which tables have an update function associated with it that I can use with the generic function. For example, some tables may be read-only and dont have an update function.
Normally, the compiler helps you out by providing a dropdown list of functions an object has that you can choose from.
Likewise, the compiler will have a dropdown list of all the different arguments (signatures) a function has.
I dont think the generic function will provide this. As an end-user calling up a Hibernate function that you wrote, I want help from the compiler on what my options are. I don't want to dig into the Hibernate configuration file to determine weather update is allowed for a table or not.
The downside of not using generics of course, is you have to write a DAO with CRUD functions for each and every table in the database (actually, for every graph, but lets not get into that).
Also, I don't see an example of how the associations between tables is implemented in generics. For example, one to many relationships, etc. A developer may get bogged down trying to get generics to work for all those possiblies (then again, perhaps not, since I didn't try it).
By the way, I don't see anything about generic DAO on the internet younger than 2 years old so I suspect it hasn't caught on.

Similar Messages

  • How to create Insert & Update on master-detail form JPA/EJB 3.0

    Is there any demonstration or tips how to Insert record on master-details form for JPA/EJB 3.0 with ADF binding?

    I have master-detail forms (dept-emp). I drag the dept->operations->create method to JSF page. But when I click create button, only dept form is clear and ready for insert. But emp form is not clear. How can I add create method for this?
    Can you give some example how to pass the right object to the persist or merge method so that it can save both the two objects (master-detail tables)
    Thanks
    Edited by: user560557 on Oct 9, 2009 8:58 AM

  • Problem when using JPA/EJB in webservice

    I wrote a web service that use JPA/EJB to connect to Sybase (the existing tables), and deployed to OC4J, but it got the following error when the web service is invoked:
    <env:Envelope
      xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:ns0="http://prjtestws_9/types/">
     <env:Body>
      <env:Fault>
       <faultcode>env:Server</faultcode>
       <faultstring>Internal Server Error (Caught exception while handling request: java.lang.NullPointerException)</faultstring>
      </env:Fault>
     </env:Body>
    </env:Envelope>
    I have checked that, the query will return some records, and also it works fine if the program executed as a stand alone application.
    Thanks in advance

    I find that I can only have ONE webservice that using JPA/EJB for an OC4J instance, if more than one then the above error will come out, and I have to restart the OC4J instance to run another webservice that using JPA/EJB.
    Is there any solution for this issue?
    Thanks

  • JPA and Generics

    Hi,
    please consider the following code snippet:
    @Entity
    @Table(name = "MS")
    @DiscriminatorColumn (name="TYPE",discriminatorType=DiscriminatorType.INTEGER)
    public abstract class MS<T extends M> implements java.io.Serializable {
        @JoinColumn(name = "M_ID", referencedColumnName = "ID")
        @ManyToOne(fetch=FetchType.LAZY)
        private T m;
    @Entity
    @DiscriminatorValue("0")
    public class BS extends MS<B> implements java.io.Serializable {
    @Entity
    @Table (name="M")
    @DiscriminatorColumn (name="TYPE",discriminatorType=DiscriminatorType.INTEGER)
    public abstract class M<T extends MS> implements java.io.Serializable {
        @OneToMany(mappedBy="m")
        private Set<T> ms = new HashSet<T>();
    @Entity
    @DiscriminatorValue("0")
    public class B extends M<BS> implements java.io.Serializable {
    }This compiles and deploys fine. However, at runtime JPA is not able
    to figure out what m in the mappedBy attribute refers to.
    It complains that it has a set of type BS which does not have the field m defined. This is true for BS
    but its super class MS has this field defined.
    So I wondering if this is a limitation of JPA or may be I configured something
    wrong!? Is a scenario like above possible with the current JPA?
    Thanks for any help.
    regards.

    No idea!? Let me give an example using Hibernate (you could replace it with JPA though):
    B b = session.get(B.class, Long.valueOf(1));
    Hibernate.initialize(b);In the initialize() process you get an exception, complaining that the Set cannot be resolved because the property m does not exist in class B (which is the type at runtime).
    So I am wondering if it is currently possible to use generics in this way with JPA/Hibernate Entity Manager?

  • ADF Model Validation using JPA/EJB stack.

    Hi,
    We are evaluating 11g and are interested in implementing using a JPA/EJB3.0/Toplink - EJB Session Bean - ADF bindings - ADF Faces RC stack.
    Looking at the declarative validation rule framework, I am trying to determine whether I can define domain model validation rules that can be propagated up through to the ADF faces RC layer. We have looked previously, at the ADF BC framework and note that it can be done there, but we wish to use a pure EJB/JPA solution.
    I can see how validation rules can be declared at the page bindings layer in the pageDef file, and this all works. However, these same validation rules applied to the Structure Definition <entitybeanname>.xml file, do not propagate up through the ADF binding layer, although the xsd of the structure definition file does appear to support it. The documentation I have read is somewhat ambigious as to whether this is possible.
    Basically, it would be nice to have some form of domain attribute validation that can be defined against the entity bean attributes that is available in the service and UI layer ala Hibernate Validator etc...
    Anyone, got any suggestions?
    regards,
    andy

    I'm not sure I understand what the "ADF own transaction operation" is. Could you explain?
    If you have to write your own persist method, what's the proper way to go about doing this? Is there a tutorial to be found somewhere? What I have now has been created by following the tutorial linked above, I haven't modified the code yet. Looking at the code I found this:
    jTable1.setModel((TableModel)panelBinding.bindUIControl("tableNameFindAll",jTable1));
    Where tableNameFindAll is related to a named query TableName.FindAll.
    There seems to be a data structure named "UpdateableCollection" which provides the operations such as 'create', 'next', 'first', etc. Would a subclass of this be the proper place to put a 'commit' function? I'm assuming through the bind control I could gain access to either this UpdateableCollection or the list of entities (List<tableName>) then I suppose I could go through this list and persist the new ones. But I think this doesn't fit with the paradigm as these are data control operations not interface operations. So I'm wondering where should I put the 'commit' operation (which should both add new data and merge the updated data) and how do I bind it to the interface? I just couldn't find a tutorial explaining all of this, but perhaps it's out there.
    Thanks.

  • Update form another EJB with DAO persistence

    We have two modules with EJB Session, stateless, with CMT requeried in all methods, the first module has the persistence tier wiht DAOs pattern and the other module uses TopLink. We are using JSF as framework in the presentation layer, when we are going to update the database from web form a backing bean JSFcalls the first EJB (DAOs persistence) and this EJB invokes the other EJB (Toplink persistence). and throws the next exception
    05/10/31 17:12:12 java.lang.NullPointerException
    05/10/31 17:12:12      at oracle.toplink.internal.indirection.UnitOfWorkValueHolder.getValueFromServerObject(UnitOfWorkValueHolder.java:105)
    05/10/31 17:12:12      at oracle.toplink.internal.indirection.UnitOfWorkValueHolder.instantiate(UnitOfWorkValueHolder.java:144)
    05/10/31 17:12:12      at oracle.toplink.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:64)
    05/10/31 17:12:12      at oracle.toplink.internal.indirection.BasicIndirectionPolicy.cloneAttribute(BasicIndirectionPolicy.java:88)
    05/10/31 17:12:12      at oracle.toplink.mappings.ForeignReferenceMapping.buildClone(ForeignReferenceMapping.java)
    05/10/31 17:12:12      at oracle.toplink.internal.descriptors.ObjectBuilder.populateAttributesForClone(ObjectBuilder.java:1492)
    05/10/31 17:12:12      at oracle.toplink.publicinterface.UnitOfWork.cloneAndRegisterNewObject(UnitOfWork.java:601)
    05/10/31 17:12:12      at oracle.toplink.publicinterface.UnitOfWork.internalRegisterObject(UnitOfWork.java:2294)
    05/10/31 17:12:12      at oracle.toplink.internal.sessions.MergeManager.registerObjectForMergeCloneIntoWorkingCopy(MergeManager.java:688)
    05/10/31 17:12:12      at oracle.toplink.internal.sessions.MergeManager.mergeChangesOfCloneIntoWorkingCopy(MergeManager.java:397)
    05/10/31 17:12:12      at oracle.toplink.internal.sessions.MergeManager.mergeChanges(MergeManager.java:181)
    05/10/31 17:12:12      at oracle.toplink.publicinterface.UnitOfWork.mergeClone(UnitOfWork.java:2634)
    05/10/31 17:12:12      at oracle.toplink.publicinterface.UnitOfWork.deepMergeClone(UnitOfWork.java:1231)
    05/10/31 17:12:12      at siscoi.declaracionescambio.business.DeclaracionesCambioMngr.grabarDeclaracionCambio(DeclaracionesCambioMngr.java:222)
    when the objects are new the TopLink framework works good, but when the object already exist in the DB, does not make the update an thorw the null pointer exception why?.
    We implements a Client Class to only test the EJB with Toplink persistence. In this class read a object from de database and i modify the object and calls the update method and the update works good.
    Container oc4j 10.1.2
    Toplink 9.0.4
    jdk 1.4.2.04
    please help me!!

    It looks like the issue is occurring because the object that you are merging is a new object, or TopLink thinks it is a new object and it is being registered as a new object. The new object has a non-instantiated value-holder that seems to have been serialized so can no longer be instantiated, but the relationship is required to persist the new object.
    My guess is that the object is not new, but existing, and the issue is most likely with your does-exist-check option. The original object may no longer be in the cache, so you most likely need to use check-database for your descriptor's does-exist option, instead of the default of check-cache.

  • A design question related to generic dao pattern

    I follow this link https://www.hibernate.org/328.html to design my DAO layer using jpa/ hibernate. And basically it works ok. However, I encounter a dilemma regarding to persistence relation between domain objects.
    My classes include
    User <--(many to many)--> Group
    Tables are USERS, USERS_GROUPS, GROUPS
    In User class, I have properties
         @JoinTable(name="USERS_GROUPS",
              joinColumns=
              @JoinColumn(name="USER_ID"),
              inverseJoinColumns=
              @JoinColumn(name="GROUP_ID")
         private List<Group> groups = new ArrayList<Group>();
         public User(String id, String account, String name, String password){
              this.id = id;
              this.account = account;
              this.name = name;
              this.password = password;
         public List<Group> getGroups(){
              return this.groups;
         public void setGroups(List<Group> groups){
              this.groups = groups;
         }In Group class,
         @ManyToMany(mappedBy="groups",fetch=FetchType.EAGER)
         private List<User> users;  
         public Group(String id, GroupName name){
              this.id = id;
              this.name = name;
         public List<User> getUsers(){
              return this.users;
         public void setUsers(List<User> users){
              this.users = users;
    ...Now in the database (mysql), I have already had two groups existing. They are
    mysql> select * from GROUPS;
    +----+------+
    | ID | NAME |
    +----+------+
    | 1  | Root |
    | 2  | User |
    +----+------+and in the table USERS_GROUPS
    mysql> select * from USERS_GROUPS;
    +--------------------------------------+----------------+
    | USER_ID                               | GROUP_ID |
    +--------------------------------------+----------------+
    | 1                                               | 1                 |
    | 1                                               | 2                 |
    +--------------------------------------+----------------+When I want to create a new user object and assig user object with an existing GROUP (e.g. GroupName.User)
    At the moment the way how I implement it is done in the DAO layer (e.g. UserDaoImpl). (But what I want is to get this procedure done in the domain object layer i.e. User class, not DAO layer. )
    steps:
    1.) search the GROUP table (entityManager.cerateQuery(" from Group").getReulstList())
    So it will return a list of all groups in GROUPS table.
    2.) then check if the group (e.g GroupName.User) I want to assign to the User object existing in the GROUP table or not.
    3.) if not existing, create a new Group and add it to a list; then User.setGroups(newList);
    or
    if the group (to be assigned to User class) already exists, use the group retrieved from the GROUP table and assign this group to the User class (e.g. groupList.add(groupFoundInGroupTable) User.setGroups(groupList))
    However, what I want to do is to encapsulate this procedure into User calss. So that in DAO class whilst performing function createUser(), it would only need to do
    User user = new User(....);
    user.addGroup(GroupName.User); // GroupName is an enum in which it contains two values - Root, User
    entityManager.merge(user);Unfortunately, because I need to obtaining Group collections from GROUP table first by using entityManager, which does not exist in the domain object (e.g. User class). So this road looks like blocked.
    I am thinking about this issue, but at the moment there is no better solution popped upon my head.
    Is there any chance that this procedure can be done more elegantly?
    I appreciate any suggestion.
    Edited by: shogun1234 on Oct 10, 2009 7:25 PM

    You should be able to link your objects using methods in your entities to create an object graph.
    When you save your user the associated objects will also be persisted based on the cascade types that you have specified on the relationships between the entities.

  • Transaction problem with stateless EJB and DAO

    Hi,
    I'm using a stateless session bean with container managed transaction and I have a method, which updates a row via CMP entity bean and then calls stored procedure, using a DAO object, which has to use the updated data. Both calls must be done in one transaction. The problem is that the stored procedure doesn't see the changes made from the update via CMP EJB, but after the method exits the changes are in the database. I'm using WebSphere 4.0.3 and DB2 7.2. Method code example in the stateless bean:
    public doIt(ValueObject vo) throws ... {
    OrderPosRemote opr = getOrderPosRemote();
    opr.update(vo);
    getDAO().recalc(vo);
    } catch (DAOException daoex) {
    getSessionContext().setRollbackOnly();
    And in the DAO:
    public boolean recalc(...) throws DAOException {
    Connection conn = getConnFromDataSource();
    CallableStatement cstmt = conn.prepareCall("call ...(?,?)");
    cstmt.execute();
    ... // close cstmt and release connection to the pool
    Any help will be highly appreciated !

    Hi meadandale,
    this was my first guess too and I set this attribute in the session bean method, then into the update method of the CMP bean and "manually" to the connection object in the DAO like this:
    conn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
    The isolation level is set correctly (IMHO), because when I comment the line above in the DAO, an exception is thrown stating that the isolation level can't be changed within a transaction.
    Unfortenully this didn't help too. Should I set some special attribute to the database or connection pool additionally ?
    I don't understand what is the problem actually - it is definitely one transaction and why this doesn't work is not very clear to me ...

  • How can i use oracle coherence with JPA/ejb  in web service?

    Hi
    I want to make web service using JPA which calls oracle XE via oracle coherence? i want to use JAX-ws? i searched and found you can make and deployed it using web logic but is there any other way i can make it and deployed in tomcat. i want to use oracle coherence + Oracle XE + JAX-WS? if it possible how can i other wise what are other ways i can do it?
    please any one does know it reply please it helps me lot to get.
    Thanks in advance,
    Edited by: 913837 on Feb 22, 2012 3:51 PM

    If you want data cached in Coherence to find it's way into an Oracle database for persistence, then look at the "CacheStore" section of the Coherence Developer Guide. This also works the other way round too, in that you can get data read into a Coherence cache via a database read. Again, look in the Coherence Developer Guide.
    If you want you applications "entry point" into a piece of code to be a web-service, then Tomcat+CXF will work just fine. Once you are in the service, just use the Coherence API to put the data in a cache.
    But also look at the HTTP access offered in later versions of Coherence in the form of REST. This may save you the Tomcat+CXF install, depending upon your needs. See the Coherence Client Guide.
    Still, what exactly are you trying to achieve here? It's not clear from your post why a web service using JPA for persistence needs to go via Coherence at all. More info needed.
    Cheers,
    Steve

  • Newbie - JDev Missing Entities from Tables (JPA/EJB 3.0) Option

    I'm trying to run through the 'Introduction to EJB3.0 Using Oracle JDeveloper and OC4J' tutorial. One of the early steps says to select the 'Entities from Tables' option under the Business Tier/EJB category. I have six options available - CMP Entity Beans from Tables, EJB Data Control Wizard, EJB Diagram for EJB1.1, 2.0 and 2.1, Entity Bean, Message-Driven Bean, and Session Bean.
    I have JDev Studio Edition Verion 10.1.3.0.4 (SU5) - Build JDEVADF_10.1.3_NT_060125.0900.3673
    I just downloaded it from OTN last week. <I>Did I miss a step somewhere?</I>

    Thank you, Andrej. It appears the tutorial has not been updated for the version of JDev I have. I was able to get a few steps further down in the tutorial, but hit more stumbling blocks. This probably isn't something for a true java newbie to try. I'll see if I can find something more in line with my experience (or lack thereof).
    Have a great evening.

  • Entities from tables (JPA EJB 3.0) creation problem

    I have a problem to get all the entities created in JDev 10.1.3.3 on UBuntu Linux, JDK 1.5.11. I think that some relations missing also. When I try to connect from my Win XP machine to the same DB (Oracle XE) everything is fine. JDev on Win machine uses JDK 1.5.06. Maybe the problem is JDK version? Any advice?
    Thanks in advance

    Thank you, Andrej. It appears the tutorial has not been updated for the version of JDev I have. I was able to get a few steps further down in the tutorial, but hit more stumbling blocks. This probably isn't something for a true java newbie to try. I'll see if I can find something more in line with my experience (or lack thereof).
    Have a great evening.

  • DAO pattern and Java Persistence API

    Hi
    This is a question for anyone who might be familiar with the standard DAO design pattern and the Java Persistence API (JPA - part of EJB3). I'm new to this technology, so apologies for any terminology aberrations.
    I am developing the overall architecture for an enterprise system. I intend to use the DAO pattern as the conceptual basis for all data access - this data will reside in a number of forms (e.g. RDBMS, flat file). In the specific case of the RDBMS, I intend to use JPA. My understanding of JPA is that it does/can support the DAO concept, but I'm struggling to get my head around how the two ideas (can be made to) relate to each other.
    For example, the DAO pattern is all about how business objects, data access objects, data transfer objects, data sources, etc relate to each other; JPA is all about entities and persistence units/contexts relate to each other. Further, JPA uses ORM, which is not a DAO concept.
    So, to summarise - can DAO and JPA work together and if so how?
    Thanks
    P.S. Please let me know if you think this topic would be more visible in another forum (e.g. EJB).

    Thanks, duffymo, that makes sense. However ... having read through numerous threads in which you voice your opinion of the DAO World According to Sun, I'd be interested to know your thoughts on the following ...
    Basically, I'm in the process of proposing an enterprise system architecture, which will use DAO as the primary persistence abstraction, and DAO + JPA in the particular case of persistence to a RDBMS. In doing so, I'd like to illustrate the various elements of the DAO pattern, a la the standard class diagram that relates BusinessObject / DataAccessObject / DataSource / TransferObject (http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html). With reference to this model, I know that you have a view on the concept of TransferObject (aka ValueObject?) - how would you depict the DAO pattern in its most generic form? Or is the concept of a generic DAO pattern compromised by the specific implementation that is used (in this case JPA)?

  • JPA Inheritance across DCs

    Hi,
    I'm trying to learn how to implement JPA inheritance across DCs.
    For this purpose, I have created one application "base" (EAR + EJB) that contains a "Person" entity supporting inheritance type JOINED. This application contains also Stateless Session Bean for managing Persons.
    A second application "top" contains an "Employee" entity that inherits from "Person". This application contains a Stateless Session Bean for managing Employees that delegates some of the calls to the Person DAO.
    When everything is together in one application, it works perfectly well. Splitting it up in two applications, I left the data-source-aliases.xml and persistence.xml in the base application the same.
    I created dependencies (both COMPILATION and ASSEMBLY) from the "top" application to the "base" application and exposed everything in these public parts.
    I also created an application reference in the "top" application application-j2ee-engine.xml.
    Now I'm getting various errors depending on how I modify the "top" application.
    I tried adding identical data-source-aliases.xml and persistence.xml files - didn't work.
    I tried adding "<jar-file>aoksystems.debottomearpp_***.jar</jar-file>" in the persistence XML and removing the <jta-data-source> tag.
    When deploying the "top" application, I get a warning in NWDS but errors in the log in NWA.
    [ERROR CODE DPL.DS.5030] Clusterwide exception: [server ID 9858650:[ERROR CODE DPL.DS.5029] Exception in operation [startApp] with application [aoksystems.de/jpasecond~ear].
    -> [ERROR CODE DPL.DS.5030] Clusterwide exception: [com.sap.engine.services.jndi.persistent.exceptions.NameNotFoundException: Object not found in lookup of JPA_DEFAULT.
    I hope the JPA gurus can help me get this to work. Thanks a lot in advance!
    Cheers,
    Thorsten

    Hi Adrian,
    Thank you for your input. I hoped very much that you would reply.
    I think I haven't motivated the situation sufficiently, so let me explain why it is not entirely pathological.
    Suppose you're constructing a contract management application for an insurance company. There are different types of insurances (life insurance, car, building), each with different data structures and business processes, but with a common core.
    Now you split the development up and say you create one component with the common core that is identical for all aspects of insurance contract management: a "contract" root entity with common attributes, DAOs for this entity, business partner management, a generic billing engine, etc.
    Furthermore, in software components on top of the core/framework, you create components for the specialties of life insurance, building insurance, and car insurance. These are dependend on the core and use its generic functions but add extra functionalities such as life-specific business processes, UIs, business logic, contract attributes in additional database tables and attributes of subclasses or classes joined through composition.
    Clearly, a cyclic dependency between life and core is not possible or desired. Core should not know life, car, and building, but its generic services should be able to operate on their objects. This architecture is quite common and nothing out of the ordinary. Life, car, and building would just use (implement) the interfaces provided by core and thus enable core to operate on their objects in a polymorphic fashion.
    Take Web Dynpro as an example. Core provides a dialogue framework that leaves some things blank and exposes WD interfaces. Life implements these interfaces. At run time, core looks up the names of life's WD DCs and components and joins them in without any static references. The reference is entirely dynamical because it relies on a configuration that is deployed with Life and not with Core.
    Now to get the same kind of behaviour for a core JPA entity and DAO seems to be problematic. The ability to operate on unknown (at design time/build time) subclasses of a known class that are deployed in an archive that is also unknown at design time but known at run time from a configuration (file, JNDI, ...) is quite normal in framework programming IMHO.
    Thanks a lot for reading through all this.
    Cheers,
    Thorsten

  • Share persistence.xml file between two EJB modules in EAR

    Hello, everybody!
    First of all, I would like to say that I already posted this question in another forum:
    [http://community.jboss.org/thread/154128?tstart=0]
    But as I haven't got any answer from there and this issue is very crucial to me I'm posting it here too in the hope that I get an answer. So, here it goes:
    I have two EJB modules in an EAR module. I would like to know how to share a single persistence.xml file with these two EJB modules. If I replicate the persistence.xml file in the two EJB modules, the EAR project deploys ok, but of course that's not what we want. If I remove the persistence.xml file from any of the EJB projects, the EAR doesn't deploy properly. I'm stuck with this. I've already tried many kind of configurations but none worked. I really would like to have some help with this issue to proceed working. This is my EAR structure:
    solicitacoes-ejb.jar       (EJB session beans)
    solicitacoes-dao.jar       (EJB interfaces)
    solicitacoes-dao-jpa.jar   (EJB session beans)
    solicitacoes-ejbClient.jar (entities and EJB interfaces)
    solicitacoes-web.war
    META-INF/This is my application.xml file:
    <?xml version="1.0" encoding="UTF-8"?>
    <application
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"
    version="5">
        <display-name>solicitacoes-ear</display-name>
        <module>
            <ejb>solicitacoes-ejb.jar</ejb>
        </module>
        <module>
            <ejb>solicitacoes-dao-jpa.jar</ejb>
        </module>
        <module>
            <web>
                <web-uri>solicitacoes-web.war</web-uri>
                <context-root>solicitacoes</context-root>
            </web>
        </module>
    </application>If I remove the persistence.xml file from one of the EJB modules, let's say solicitacoes-dao-jpa.jar, I get this error when deploying the EAR file:
    ... 39 more
    Caused by: java.lang.IllegalArgumentException: Can't find a persistence unit named 'null' in AbstractVFSDeploymentContext@28359170{vfs:///C:/jboss-6.0.0.20100429-M3/server/default/deploy/solicitacoes-ear.ear/solicitacoes-dao-jpa.jar/}
    at org.jboss.jpa.resolvers.BasePersistenceUnitDependencyResolver.resolvePersistenceUnitSupplier(BasePersistenceUnitDependencyResolver.java:107) [:1.0.2-alpha-1]
    at org.jboss.ejb3.Ejb3Deployment.resolvePersistenceUnitSupplier(Ejb3Deployment.java:778) [:1.3.1]
    at org.jboss.ejb3.EJBContainer.resolvePersistenceUnitSupplier(EJBContainer.java:1517) [:1.3.1]
    at org.jboss.injection.PersistenceUnitHandler.addPUDependency(PersistenceUnitHandler.java:130) [:1.3.1]
    ... 43 moreI need help with this issue. As you could see, the EJB container doesn't like to see an EJB module without a persistence.xml file. This is clearly a dumb decision though. I agree with it if there was only one EJB module in an EAR. But the container should have been smart enough to require only one persistence.xml file in an EAR module with more than one EJB module, and share that persistece context with the whole EAR.
    Acting the way it is acting now, the container forces us to duplicate the persistece.xml file and kill our application modularity. This is clearly wrong. I've already tried to put the entity classes and persistence.xml file in the lib directory of the EAR, but it didn't work either. The container needs to have the persistence.xml file in both EJB modules.
    I don't know if this is a JBoss implementation decision or if it comes from the Java EE 6 specification. Whatever it is, it goes against all good modular and good design decision. Please if some of you know how to solve this, took a little time to tell me how. I would be very grateful.
    Thank you in advance.
    Marcos

    Dear Mr. gimbal2,
    In another occasion I would not reply to such a 'helpful' answer like the one you gave me (yes, it is undoubtedly an answer because that's how you classified it in the beginning of your reply), but as today I have plenty of time here in my job, for this week we're not working full time as usual, I decided to reply to it.
    You have to completely overhaul your attitude.I really didn't know I was taking so personal on this issue to have to 'completely overhaul my attitude'. Thank you for pointing that out.
    In stead of calling the technology dumb, admit to yourself that perhaps you don't understand it properly and that your ideas of what is correct design perhaps is a little lacking. I didn't call the technology dumb because I stated very clearly that I don't know for sure if it is working this way. I said in the last paragraph:
    +"I don't know if this is a JBoss implementation decision or if it comes from the Java EE 6 specification. Whatever it is, it goes against all good modular and good design decision."+
    So, I let implicit the fact that the technology or the implementation of the technology is dumb only if it doesn't allow this possibility. Regarding the fact that your said that I should
    admit to myself that perhaps I don't understand it properly, where did I stated in my question that I understand it completely? It's clear in the last paragraph that I don't. If I'm asking that's because I have doubts. Maybe my ideas of what is correct is wrong, and that's why I'm here in this forum. But everyone with a good sense knows that what I propose in this discussion is by no means a wrong design decision. Where is it a sin to have more than one EJB module in a EAR and a persisntece.xml file shared for the whole EAR? Does everyone that has more than one EJB module in an EAR module need to connect to more than one database? Is it wrong to want to have your DAO implementation in a separate EJB module in order to make deployment easy and also changes, if you later want to replace that implementation with another one without affecting
    the other modules? I don't think that a design decision that seeks this is lacking. I don't think that Java EE today is a dumb technoloby, but everyone knows that before it gets to the present level, it was a technology known to have made big dumb decisions that the community latter corrected, with ideas like O/R mapping (Hibernate), dependency injection (Spring), Struts and lots of other examples that we all know. No one can deny this and lots of wrong things will continue to be fixed in later releases.
    Maybe when you rise yourself back to that level, you open yourself up again to thinking in correct solutions in stead of trying to hammer through your own poorly chosen one.To be sincere, I see you took very personal about this issue. You really shows to be someone that has no respect to other people and you judge them too. I must say that I got surprised by the way you answered my post. I didn't expect to get such sarcastic answer to what I asked. I personally don't act this way. If I can't help a person, I also don't try to ridicularize him.
    Marcos

  • DAO Pattern and the ServiceLocator

    I have been developing a lightweight framework for working with AIR and the SQL API. This framework has no dependencies on Cairngorm however it is built around a typical DAO implementation.
    While developing this I considered how it should be integrated with Cairngorm, which lead me to wonder if a simple DAO marker interface which could be retrieved from the ServiceLocator (and cast to the correct abstraction by a business delegate) would not be all that is needed to have a rather flexible service layer in Cairngorm?
    For example, consider the following pseudo code which is what I would imagine a business delegate to look like:
    class FooDelegate {
    protected fooDAO:IFooDAO;
    public FooDelegate(responder:IResponder) {
    fooDAO = ServiceLocator.getinstance().getDAO(Service.FOODAO) as IFooDAO;
    fooDAO.addResponder( responder );
    public getFoo() void {
    fooDAO.getFoo();
    public addFoo(foo:IFoo) {
    fooDAO.addFoo(foo);
    public deleteFoo(foo:IFoo) {
    fooDAO.deleteFoo(foo);
    As you can see the delegate would cast the dao to the correct abstraction and then just wrap the DAOs API (somewhat similar to an Assembler in LCDS).
    A custom DAO interface would extend the DAO marker interface so that the ServiceLocator could find it:
    interface IFooDAO extends IDAO
    getFoo() void;
    addFoo(foo:IFoo);
    deleteFoo(foo:IFoo);
    Service.mxml would define an instance of the dao as an abstraction and then call a factory to get the appropriate implementation:
    public fooDAO:IFooDAO = DAOFactory.getDAO("foo");
    I see much potential in this type of implementation as it would allow services to be swaped out with different implementations via a config or with an IoC implementation etc, thus allowing the services themselves to be completely transparent to client code.
    I wanted to see if anyone had any thoughts on this as well?
    Best,
    Eric

    Thanks, duffymo, that makes sense. However ... having read through numerous threads in which you voice your opinion of the DAO World According to Sun, I'd be interested to know your thoughts on the following ...
    Basically, I'm in the process of proposing an enterprise system architecture, which will use DAO as the primary persistence abstraction, and DAO + JPA in the particular case of persistence to a RDBMS. In doing so, I'd like to illustrate the various elements of the DAO pattern, a la the standard class diagram that relates BusinessObject / DataAccessObject / DataSource / TransferObject (http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html). With reference to this model, I know that you have a view on the concept of TransferObject (aka ValueObject?) - how would you depict the DAO pattern in its most generic form? Or is the concept of a generic DAO pattern compromised by the specific implementation that is used (in this case JPA)?

Maybe you are looking for

  • Can someone else confirm this bug or is it just me?

    I think I've run into another *choose file name* bug. I have a script which uses the text returned from a *display dialog* command to gather part of the file name for a *choose file name* command. I usually paste the other part of the file name in of

  • Moving all records- old  code (G/L/Cust/Vend) to new code (G/L/Cust/Vend)

    Hi Friends, I have created a customer code (say for e.g. C001 for  ABC LTD.), and did some SD & FI transactions (data entry) using that code. After few days, I realized that this above stated customer code (C001) is not correct. So I blocked this cus

  • Creating row based on a CombinedView

    Hi guys, I got the following situation in Java Client with BC4J: 1. I created a CombinedView based on 2 tables which have a relationship (1 to 1). 2. I generated an application with Jclient which ask for the two tables' values at the same time. 3. I

  • Exporting Metadata in V3.4.5 appears NOT to work

    What I want to do is export selected metadata, or perhaps a metadata view, for selected images to a CSV file, or to a spreadsheet file for further analysis. No matter what I try I cannot get anything remotely useful. Here is what I get when selecting

  • Crack in MacBook Pro Screen

    Hello, I am not entirely sure how it happened, but in the right corner of the glass of my 13" MacBook Pro screen there is a crack stretching down to the bottom of that portion of the screen. There is nothing wrong with any other part of the screen, j