TopLink Entity Creation Factory

Is there a way I can customize the creation of the entities specified in persistence.xml? Instead of TopLink creating them, I'd like to create them myself using and then pass it on to TopLink? I'm looking for something like an ObjectFactory that I can implement and have TopLink use it. Is this possible?

I'm looking
for something like an ObjectFactory that I can
implement and have TopLink use it. Is this possible?In both Oracle TopLink and TopLink Essentials you can configure a descriptor's instantiation policy to use an Object Factory.
In Oracle TopLink you'd define an afterLoad method to customize the descriptor and in Essentials you'd define a customizer. Either way, the code to set the factory is the same. There are a number of variants of the useFactoryInstantiationPolicy method so use the one that best suits your needs. Here's one usage:
descriptor.getInstantiationPolicy().useFactoryInstantiationPolicy(MyFactory.class, "create");In this example, when TopLink needs to create an instance of the class of this descriptor, it'll call the static "create" method on MyFactory.
--Shaun                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Dynamic Query Mapping using Toplink Entity

    Hi,
    We have a requirement that the column names of the table dynamically gets changed for different customers.
    eg;
    Client 1 , will have
    Select EMP_ID, EMP_NAME from EMPLOYEE
    Client 2 will have
    SELECT CEMP_ID, EMP_NAME, CEMP_ADDR from EMPLOYEE
    Is it possible to make a Toplink Entity Employee object to support both the queries at runtime ?ie; we should not modify the java entity object for each customer.
    With normal JDBC , we can perform SELECT * from EMPLOYEE ,get the resultset , and using metadata , we can find the column names and process it accordingly.
    Is this functionality possible with toplink JPA at all ?
    Thanks
    prabu

    Hi,
    I am trying to use DynamicEntity class. Is Joined Table Inheritance supported in DynamicEntity ? Since I need to create an HybridEntity on the fly by selecting all the fields from TABLE A and TABLE B by joining key fields, whose fields will dynamically change based upon the customer. Below is what I am currently trying to do. But the Entity Object that I got contains fields only from TABLE A and not from TABLE B
    EntityManagerFactory emf = new EntityManagerFactoryImpl(setup,EclipseLinkJPATest.getEMFProperties());
    SchemaManager manager = new SchemaManager(JpaHelper.getServerSession(emf));
    Vector <DatabaseRecord>tableAEntityFieldNames = manager.getAllColumnNames("TABLE A");
    Vector <DatabaseRecord>tableBFieldNames = manager.getAllColumnNames("TABLE B");
    EntityType tableAType = EntityTypeFactory.create("TableAEntity","DynamicEntity$TableAEntity", "TABLE A", loader);
    String columnName = null;
    for(DatabaseRecord tableAObj: tableAEntityFieldNames){
    columnName = tableAObj.get("COLUMN_NAME").toString();
    EntityTypeFactory.addBasicProperty(tableAType, columnName, columnName,
    "TABLE A_ID".equals(columnName) ? Long.class : String.class, "TABLE A_ID".equals(columnName) ? true : false);
    EntityTypeFactory.addToPersistenceUnit(emf, tableAType);
    EntityType stepType = EntityTypeFactory.create("TableBEntity","DynamicEntity$TableBEntity", "TABLE B", loader);
    for(DatabaseRecord tableBObj: tableBEntityFieldNames) { 
    columnName = tableBObj.get("COLUMN_NAME").toString();
    EntityTypeFactory.addBasicProperty(tableBType, columnName, columnName,"TABLE B_ID".equals(columnName) ? Long.class : String.class, "TABLE B_ID".equals(columnName) ? true : false);
    EntityTypeFactory.addToPersistenceUnit(emf, tableBType);
    EntityManager em = emf.createEntityManager();
    List <DynamicEntity> entityList = null;
    entityList = em.createQuery("select s from TableAEntity s, TableBEntity st where s.TABLE A_ID= st.TABLE B_IDand s.TABLE A_ID=?1")
              .setParameter(1, 1397)
              .getResultList();
    System.out.println("entityList..."+entityList);
    Thanks
    Prabu

  • How to inherit one enity method and to create entity manager factory

    Hi All,
    i have totally 5 databases where one database has the connection details of all other 4 databases.i am using EJB 3.0 and using MVC architecture.is there any possibility to get the details in that datbase and create entity manager factory based on that detail.i defined all the database connection in persistence.xml.

    Hi,
    is there any oher possibility to create entity manager factory dynamically?

  • View and Entity creation source code

    I would like to know which jars \ classes in JDeveloper are responsible for writing the XML that defines a view or an entity (The XML created by the "Create a new view" wizard). Thanks.

    The designtime class responsible for Entity creation is oracle.jbo.dt.objects.JboEntity and the class for View Objects is oracle.jbo.dt.objects.JboView. There is no documentation available for how the designtime apis work, so you are kind of on your own to do much with it.
    Ray

  • Dynamic domain-based entity creation and relation to base entity

    Hi everyone -
    My first post here...  I have a base entity (PROJECT) with an attribute called RecordType (a domain-based attribute).  Depending on the value of RecordType, the business wants to use that result set as input for another reference entity, and then
    relate them together in a possible {one|many}-to-many relationship.  For example:
    If RecordType = Strategy, then there is a need to create a separate entity called STRATEGY with the results of that filter.  The PROJECT entity and STRATEGY now need to be related together in a PROJECT_STRATEGY relationship table.
    There seem to be a couple of options, but none are elegant, and some simply don't work:
    Option #1 (doesn't work): I create the relationship table (PROJECT_STRATEGY) with a domain-based attribute of the PROJECT entity and a second domain-based attribute of the PROJECT entity (but called Strategy), and then try to create a business
    rule that limits the selection of the second domain-based attribute by RecordType.  MDS tells me I can't use a domain-based attribute in the business rule.
    Option #2: I create a SQL Server view called STRATEGY (which is a query based on the PROJECT entity - "where RecordType = 'Strategy') and use that as the reference set.  However, there is now no way to utilize that result set inside MDS. 
    In other words, I cannot use it as a domain-based attribute in the PROJECT_STRATEGY relationship table.  This means that an external system/UI would need to enable the relationship selection and write back into the PROJECT_STRATEGY relationship table
    inside MDS.
    Option #3: I create a STRATEGY entity that is auto-updated (via SQL Server job) every 10 minutes or so from the PROJECT entity (can't figure out how to load a reference entity based on a result set from an existing entity).  This allows me to create
    two domain-based attributes in the PROJECT_STRATEGY table (as described in Option #1), but is also what I call a non-standard customization, so I have been reticent to go this route.
    So, my questions/comments are:
    Is there any way to make Option #1 work (using business rules)?
    Option #2: Our development team doesn't want to create a separate system/UI to relate the list of PROJECTs to the list of STRATEGYs and then write them back into the PROJECT_STRATEGY relationship table.  This also limits the ability to maintain the
    PROJECT_STRATEGY table inside MDS since the STRATEGY domain-based attribute would become a free-form attribute at that point.  Is there any way to register a view as a reference entity?
    Should I explore Option #3?  Non-standard, non-native functionality introduced into MDS (any system, really) is something I wanted to avoid, but only from a purity and possible upgrade standpoint.  Should I get over this?
    I have looked at derived and explicit hierarchies for the PROJECT entity, but they do not seem to apply in the scenario above.
    Has anyone tried to create {one|many}-to-many relationships between a base entity and a subset of that base entity without resorting to non-standard customizations within MDS?  Is this as bizarre as it sounds?
    Any help would be greatly appreciated.
    Thanks.

    Hi,
    I f you are going with rtti approach.... for dynamic creation....you can assign the checktable field in field cat
    ls_fcat-ref_table  = space.
        ls_fcat-ref_table  = 'ZST_DISTRIBUTED_EFFORT'.
        ls_fcat-ref_field  = 'WORK_EFFORT'.
        ls_fcat-rollname   = 'DPR_TV_EFFORT'.
        ls_fcat-domname    = 'DPR_WORK'.
        ls_fcat-reptext    = ls_fcat-fieldname.
        ls_fcat-scrtext_l  = ls_fcat-fieldname.
        ls_fcat-scrtext_m  = ls_fcat-fieldname.
        ls_fcat-scrtext_s  = ls_fcat-fieldname.
        ls_fcat-emphasize  = me->gc_flag_enable.
        ls_fcat-col_pos    = lv_counter.
    ls_fcat-checktable = ' '.
        APPEND ls_fcat TO lt_fcat.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog           = lt_fcat
        IMPORTING
          ep_table                  = et_dynamic_table
        EXCEPTIONS
          generate_subpool_dir_full = 1
          OTHERS                    = 2.
      IF sy-subrc NE 0.
        es_message-id         = sy-msgid.
        es_message-type       = sy-msgty.
        es_message-number     = sy-msgno.
        es_message-message_v1 = sy-msgv1.
        es_message-message_v2 = sy-msgv2.
        es_message-message_v3 = sy-msgv3.
        es_message-message_v4 = sy-msgv4.
    Thanks,
    Shailaja Ainala.

  • BTItemPriceAgreements - entity creation as relation to BTOrderItemAll

    Hi,
    I have to create items in Sales contracts through BOL logic. In the Component, I created event for this purpose. I am able to create items  by creating entities BTOrderITemAll. For the item, I need to create price agreements. When I am trying to create BTItemPriceAgreements -  system is throwing message - not allowing creation as related entity. Appreciate any inputs on how to create BTItemPriceAgreements and link to Item.
    With regards,
    Ravi

    Hi,
           I did a similar thing, in the approach that i followed i had to do the code for saving in the BTIL class (CL_CRM_METHODS_BTIL), SAVE_ORDERS method, by creating implicit enhancement at the end, there i called my Z-Function module to save in update task, so that whole transaction gets saved at a go or nothing is saved.
    Though just display a Z-table on UI as entirely different story, but this wiki link can give some pointers.
    [ZTable in Asign Block|http://wiki.sdn.sap.com/wiki/display/CRM/Howtodisplayaz-tableinanassignmentblock]
    Let me know if it helped.
    Thanks,
    Rohit
    Edited by: Rohit Khetarpal on Nov 26, 2009 4:21 PM

  • EXTERNAL PARAMETER ENTITY  CREATION

    Hi All
    I am creation the XML file using SAP XML DOM Library objects.
    Our requirement is to create the EXTERNAL PARAMETER ENTITY Declaration using DOCTYPE tag.
    For Example
    <!DOCTYPE descriptSol [
    <!ENTITY % references SYSTEM "P_899200_SD01_01.ref">;
    %references
    ]>
    We are using following method to create it:
    DATA:
    lo_doc_type                 TYPE REF TO if_ixml_document_type,
    lo_entity_dec               TYPE REF TO if_ixml_entity_decl,
              CALL METHOD go_document->create_document_type
                EXPORTING
                  name =  'descriptSol'
                RECEIVING
                  rval = lo_doc_type.
              CALL METHOD go_document->set_document_type
                EXPORTING
                  document_type = lo_doc_type.
              CALL METHOD lo_doc_type->create_ext_entity_decl
                EXPORTING
                  is_parameter_entity = 'X'
                  name                            = 'references'
                  notation                       = ''
                  public_id                      = ''
                  system_id                   = 'P_899200_SD01_01.ref'
                RECEIVING
                  rval                               = lo_entity_dec
              CALL METHOD lo_doc_type->append_child
                EXPORTING
                  new_child = lo_entity_dec
                RECEIVING
                  rval      = lw_rval.
    The Above code is working and creating following tag in the XML document:
    <!DOCTYPE descriptSol [
    <!ENTITY % references SYSTEM "P_899200_SD01_01.ref">;
    ]>;
    So hereu201D%referencesu201D at end of the declaration is missing.
    This type of entity is called as "EXTERNAL (PARSED) PARAMETER ENTITY Declaration".
    Give your suggestions that whether we are using right method to created External entity reference or not.
    Thanks in advance
    Sukhjinder Singh

    I have the same experience. After I correct the error in my dtd file, the message dissapears. Good luck.

  • Business components: detail entity creation

    Hi,
    Using JDeveloper 10.1.3.1.0.
    I've got a master-detail relationship between two entities. To do CRUD operations, I always go through the view objects based on these entities. My problem is when I create a new instance of the detail, it seems the association at the entity level is not maintained before commit.
    For example, let's say I have the entities EntityMaster and EntityDetail and the view objects ViewMaster and ViewDetail. There's an association at the entity level and a view link at the view level. This is a one-to-many relationship (one master - many details).
    I do the following in an application module method:
    ViewObject detailView = getViewDetail(); //returns the detail view object.
    Row newRow = detailView.createRow(); //create a new view row backed by an entity row
    // initialize the new row
    detailView.insertRow(newRow); //insert the row in the view.
    // a bit further
    EntityMasterImpl master = ...; //obtain somehow a reference on the master.
    RowIterator detailEntityIterator = master.getDetailEntity(); //get the detail entity iterator
    int count = detailEntityIterator.getRowCount(); //count has not been incremented by one.
    Since I have a validation on the master entity that checks if there's at least one detail entity when setting a particular attribute, I really need the association to be maintained at the entity level.
    I've worked around the problem by inserting the new detail entity row in the detailEntityIterator like this:
    newRow.getDetailEntity().getMasterEntity().getDetailEntity().insertRow(newRow);
    It does not seem to me like an elegant solution and I really feel the association should be maintained at the entity level automatically.
    Is this a bug or is there any other (more elegant) workaround?
    Thank you,
    Olivier

    Hi Steve,
    This is not a composition association. Actually, this is an association from a table to an intersection (many-to-many) table. The code in my service is based on the SRDemo, see SRServiceImpl#updateSkillsForCurrentStaff(List) and is called on a save button from a shuttle page.
    The current master is the master I want it to belong to. The link to the master gets correctly saved in the database (just as in the SRDemo). We can also navigate from the master view row to the find the detail view row using the generated RowIterator. However, this does not work from the master entity row to the detail entity row. The problem is really at the entity level.
    Thanx
    Olivier

  • Using Stored Procedures with TopLink / JPA : Success explanation

    For those who have to use Stored Procedures in TopLink this is my success history :
    To call an Stored Procedure from the persistence, we have to use the direct JDBC connection because my TopLink version ( Essentials 10g ) ? to date ( 10g ) does not have support for Stored Procedures.
    Here is my code :
    <address>{color:#0000ff} EntityManagerFactory JPAemfactory = null;{color}</address>
    <address>{color:#0000ff} JPAemfactory = Persistence.createEntityManagerFactory ("MyPersistenceUnit"); // this is the name of the persistence unit wrote in the persistence.xml file{color}</address>
    <address>{color:#0000ff} EntityManagerr MyEntityManager = JPAemfactory.createEntityManager ();{color}</address>
    bq. <address>{color:#0000ff}// creation of the stored procedure calling string .... one question mark for every param, output included \\ String sql = "{call SP_GETLISTATARIFAS(?,?,?,?,?)}"; \\ // We get the JDBC connection \\ oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl entityManager = (oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl) MyEntityManager; \\ UnitOfWorkImpl uow = (UnitOfWorkImpl)entityManager.getUnitOfWork(); \\ // we create a request to the unitofwork because if dont the connection will not exist \\ uow.beginEarlyTransaction(); \\ Connection conexion = ((UnitOfWorkImpl)uow).getAccessor().getConnection(); \\ {color}{color:#0000ff} \\ try { \\ // Creation of the call and we will identify the params as they are in the stored procedure definitiondefinidos \\ CallableStatement call = conexion.prepareCall(sql); \\ {color}</address>
    bq. <address>{color:#0000ff} \\ // params INPUT with their values \\ call.setString("pIDMCUPO", "125"); \\ call.setString("pCODIGOHOT", "8023"); \\ call.setString("pCODCANAL", "WEB"); \\ call.setString("pCODSUBCANAL", "HOTEL"); \\ {color}</address><address>{color:#0000ff} \\ // params OUTPUT \\ call.registerOutParameter("rRESULTADO", java.sql.Types.VARCHAR); \\ {color}</address><address>{color:#0000ff} \\ // execution \\ call.execute(); \\ {color}</address><address>{color:#0000ff} \\ // getting the response \\ mcontratos_out = call.getString("rRESULTADO"); \\ {color}</address><address>{color:#0000ff} \\ // closing the proc \\ call.close(); \\ {color}</address><address>{color:#0000ff} \\ } catch (SQLException ex) { {color}</address><address>{color:#0000ff} // something you do if there is an error \\ {color}</address><address>{color:#0000ff} \\ } {color}</address>
    Hope this helps all the people that have searched a lot like me.......

    I have my entity manager setup in a singleton.
    I'm finding it's costly to generate the emf, but if I don't close the em (enitity manager) and emf (entity manager factory) my open cursor count climbs until I exceed the max number of open cursors on the database (11g RAC)
    I'm committing the connection, and uow, and closing the em at the end of each call.
    But until I close the emf, the open cursors aren't released.
    TransactionhistoryPkg tranPkg = new TransactionhistoryPkg(conn); //Class created over database package via JPublisher
    tranPkg.transactionhistoryInsSp(insertTrans.getCardId()); // executes db package
    tranPkg.closeConnection();
    conn.commit();
    uow.commit();
    uow.getAccessor().decrementCallCount();
    em.close();
    Am I missing something really obvious here??
    btw - I found this link helpful in troubleshooting the max cursors issue: https://support.bea.com/application_content/product_portlets/support_patterns/wls/InvestigatingORA-1000MaximumOpenCursorsExceededPattern.html

  • Recommended way of getting entity manager from pojo class

    Hi,
    In our application we have the need or retrieving entity manager from 'pojo' classes.
    More specifically we have singleton classes which act as 'data' repositories and are accessed from both servlets and ejb.
    I'm aware that the repositories classes might be problematic, but in the current stage we can't perform significant change in application structure so I am looking for a 'fast' solution as possible.
    The best way will be to lookup entityt manager in JNDI, but as I undestand this feature is not avaialabe in weblogic.
    I understand that the preffered way for getting entity manager in such situation is by using @PersistenceUnit annotion on the calling location and lookup entityManager by that name in the pojo. This is however problematic for us since since we access the repositories from variouse locations (many different classes).
    Possible additional solutions we thought of:
    - creating an 'entity manager factory' locator ejb. This is an ejb with no transaction attribute, which has one method getEntityManagerFactory. It injects entityManagerFactory and returns it. This is the fastest soltion to implement. Is this a valid one?
    - using application managed entity manager in such situations. We have a problem doing so now because the creation seems to fail for variouse reasons.
    What is the recommended way?
    Thanks.

    To obtain an EntityManager instance, first must obtain an EntityManagerFactory instance by injecting it into the application component by means of the javax.persistence.PersistenceUnit annotation:
    @PersistenceUnit
    EntityManagerFactory emf;
    Then, obtain an EntityManager from the EntityManagerFactory instance:
    EntityManager em = emf.createEntityManager();
    http://download.oracle.com/javaee/5/tutorial/doc/bnbqw.html
    Edited by: dvohra16 on Apr 14, 2011 5:06 PM

  • JPA and Entity manager.

    Hi all,
    I have a "simple" question:
    Should I create a class to manage entity manager and entity manager factory on JPA2?
    Why do I ask that? Because I read on J2EE tutorial:
    With a container-managed entity manager, an EntityManager instance’s persistence context is automatically propagated by the container to all application components that use the EntityManager instance within a single Java Transaction Architecture (JTA) transaction.
    To obtain an EntityManager instance, inject the entity manager into the application component:
    @PersistenceContext
    EntityManager em;
    I'm using JSF2, JPA2, JTA and Glassfish3.1 on the NetBeans 7.0.1.
    The wizard that creates the JSF's pages from entity class does a good work but I have some problem in the other classes.
    When I call EntityManager it returns null!
    The strange thing is that it works properly the first time, when I recall the EntityManager from another xhtml page and from another class the entity manager returns NULL!
    So I would understand if the creation of a class for manage the EntityManagerFactory and EntityManager could help me.
    Thank you for your future help!

    Filippo Tenaglia wrote:
    Hi all,
    I have a "simple" question:
    Should I create a class to manage entity manager and entity manager factory on JPA2?That question is far from complete, as the answer to this one is "depends on what you want to do!"
    Why do I ask that? Because I read on J2EE tutorial:
    With a container-managed entity manager, an EntityManager instance’s persistence context is automatically propagated by the container to all application components that use the EntityManager instance within a single Java Transaction Architecture (JTA) transaction.
    To obtain an EntityManager instance, inject the entity manager into the application component:
    @PersistenceContext
    EntityManager em;
    Given this information...
    I'm using JSF2, JPA2, JTA and Glassfish3.1 on the NetBeans 7.0.1.That answer to your question is "NO", because you have a container available to you that can do the work (Glassfish). It makes no sense using Glassfish and then purposely ignoring the features it has to offer.
    Lets get back to basics: you are doing something wrong here. You have to figure out what, you can only do that if you keep studying and getting a more complete understanding. If you are having trouble realizing that, perhaps you should start over without the help of any wizard at all; wizards are only useful when you are already experienced, right now the fact that code is generated is hindering you a lot because you will have a strong impulse to believe there can be no mistake; unfortunately there is no such safety net. The fact that you used the word "weird" is enough proof of this by the way. There is nothing weird here, just a mistake being made that has to be corrected.
    And for the future: what IDE (Netbeans in your case) you use to develop really makes absolutely no difference at all. What is more interesting is which version of Java your are using, which can likely be Java 6 or Java 7 nowadays.

  • Toplink with stored procedures

    Hi
    I am new to Toplink and would like to get an idea whether Toplink would be suitable for our application. Currently, in our application we always access the database through stored procedures. I realize Toplink supports stored procuedres with StoredProcedureCall class. However; I am just trying to get some feedback as to whether using only this feature(as well as handling database connections etc.) of Toplink is a good idea or not.
    Thanks,
    Izi

    I have my entity manager setup in a singleton.
    I'm finding it's costly to generate the emf, but if I don't close the em (enitity manager) and emf (entity manager factory) my open cursor count climbs until I exceed the max number of open cursors on the database (11g RAC)
    I'm committing the connection, and uow, and closing the em at the end of each call.
    But until I close the emf, the open cursors aren't released.
    TransactionhistoryPkg tranPkg = new TransactionhistoryPkg(conn); //Class created over database package via JPublisher
    tranPkg.transactionhistoryInsSp(insertTrans.getCardId()); // executes db package
    tranPkg.closeConnection();
    conn.commit();
    uow.commit();
    uow.getAccessor().decrementCallCount();
    em.close();
    Am I missing something really obvious here??
    btw - I found this link helpful in troubleshooting the max cursors issue: https://support.bea.com/application_content/product_portlets/support_patterns/wls/InvestigatingORA-1000MaximumOpenCursorsExceededPattern.html

  • Re: junit test for entity beans ... ejb 3.0

    I'm confused. I'm trying to test my entity bean.
    I have:
    - an entity bean
    - a stateless session bean for accessing the entity bean (facade)
    - an interface for accessing the the stateless bean
    And I'm trying to write a JUnit test class to test this bean. However, I am uncertain as to how to test this (I'm new to EJB 3.0, JBoss and Eclipse).
    What would the JUnit test look like? I'm confused as to whether or not I should be injecting the interface/bean/what???
    I've tried several variations. I either get "NameNotFound" - not bound exceptions or Null pointer exceptions.
    What would the @EJB syntax look like or how would I do it through the context?
    For Example:
    @EJB private TestFacade myTest; //interface to stateless bean ?
    OR
    InitialContext ctx = new InitialContext();
    TestResultFacadeBean myTest = (TestResultFacadeBean) ctx.lookup("localTest");
    I'm confused at to which method I should be using and what object I should be accessing. If I could get either one to work, I'd be happy. :)
    How do I ensure my bean is deployed to the container? What do I need to do?
    If anyone has a simple example or explanation as to which method I should use and how to use it, I'd be very grateful.
    Thanks very much,
    LisaD

    OK, you need to have several layers of testing.
    Layer 0. Test the entity beans are deployable (more on this later). Basically, you need to know that all your annotations work. Things to watch out for are multiple @Id fields in one class or @EmbeddedID or @IdClass in conjuction with @ManyToOne, @ManyToMany, @OneToMany, @OneToOne and fun with @JoinTable, @JoinColumn and @JoinColumns. Once you know how these are supposed to work with the spec, it's not too bad to write it correctly each time. But there are some gotchas that will break things later on.
    Layer 1. Do the functions in the classes that don't depend on annotations work as expected. Typically, this is just going to be the getters and setters in your entity classes. Of course JUnit best practice says we don't bother testing functions that look like:
    public T getX() {
    return this.x;
    or
    public void setX(T x) {
    this.x = x;
    as there is nothing that can go wrong with them. So in that case, your level 1 tests will just be initial values specified from constructors and verifying that the non-get/set pairs work, and that the getters you have tagged @Transient work (because you've likely put some logic in them)
    Layer 2. Test the session bean methods that don't require injection to work.
    Layer 3. Test the session bean methods that require injection (Mock Objects). Simulate the injection for yourself, injecting Mock Objects for the entity manager. Then you can confirm that the correct methods are being called in the correct sequences, etc.
    [Note this may require some skill in designing the mock.  I'm working on developing my own entitymanager mock, and if it looks usefull I'll release it to the world.
    Layer 4. Test the session bean methods that require injection (Real entity manager) (See Layer 0)
    For this you will need an out of container persistence implementation.  Currently Hibernate and Glassfish provide beta versions.  You will need a different persistence.xml file that lists all the entities.  You will have to use reflection to inject the entity manager(s) that you create from an entity manager factory unless you provide a constructor that takes an EntityManager as a parameter.  You may need to use reflection to call any @PostConstruct method if you made it private.
    Layer 5. Navigate the relationships in the objects returned from Layer 4 using a database that has been loaded with test data.
    I am currently using Layers 0, 1, 2 & 4 to test my session beans and entity beans.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Org.springframework.beans.factory.BeanCreationException

    In the perisistence.xml we are configured the subscription jndi, calling using this applicationContext.xml.
    But our problem is that subscription jndi should be configured in jboss locally.
    Where we have to configured that jndi in local server. I have given the applicationContext and persistence.xml file blow:
    Also we have subscription-ds file in deploy folder of my JBoss5.1.2.
    When ever we are going to run the testcases it throwing following Exception:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: subscription not bound
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
    at com.hungama.subscription.test.LogUtilTest.<init>(LogUtilTest.java:20)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:209)
    at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:258)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:255)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    Caused by: javax.naming.NameNotFoundException: subscription not bound
    at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)
    at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)
    at org.jnp.server.NamingServer.getObject(NamingServer.java:785)
    at org.jnp.server.NamingServer.lookup(NamingServer.java:443)
    at sun.reflect.GeneratedMethodAccessor266.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
    at sun.rmi.transport.Transport$1.run(Transport.java:159)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
    at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
    at sun.rmi.server.UnicastRef.invoke(Unknown Source)
    at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:750)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:710)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155)
    at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:88)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:153)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
    at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
    at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:200)
    at org.springframework.jndi.Jndi
    Following is my persistence.xml file which i kept in META-INF/persistence.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <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="subscriptionUnitName" transaction-type="JTA">
              <provider>org.hibernate.ejb.HibernatePersistence</provider>
              <jta-data-source>java:/subscriptionDS</jta-data-source>
              <properties>
                   <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
                   <!-- <property name="hibernate.hbm2ddl.auto" value="update"/> -->
                   <property name="hibernate.show_sql" value="false"/>
                   <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
                   <property name="jboss.entity.manager.jndi.name" value="java:/subscription"/>
                   <property name="jboss.entity.manager.factory.jndi.name" value="java:/subscriptionFactory"/>
              </properties>
         </persistence-unit>
    </persistence>
    My applicationContext.sml file looks like:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:tx="http://www.springframework.org/schema/tx"
         xsi:schemaLocation="
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
         http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
         http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
    <util:properties id="chrgingProperties" location="classpath:charging-jndi.properties"/>
    <util:properties id="msgingProperties" location="classpath:messaging-jndi.properties"/>
    <bean id="jndiPropeties" class="com.myCompany.subscription.services.config.model.JNDIProperties">
              <property name="msgingProperties" ref="msgingProperties"></property>
              <property name="chrgingProperties" ref="chrgingProperties"></property>
    </bean>
              <jee:jndi-lookup id="entityManagerFactory" jndi-name="java:/subscription"></jee:jndi-lookup>
              <jee:jndi-lookup id="dataSource" jndi-name="java:/subscriptionDS"></jee:jndi-lookup>
              <bean id="trasactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
                   <property name="transactionManagerName" value="java:/TransactionManager"/>
         <property name="userTransactionName" value="UserTransaction"/>          
              </bean>
              <aop:config>
              <aop:pointcut id="productServiceMethods" expression="execution(* com.myCompany.subscription.services.impl.*.*(..))"/>
              <aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods"/>
              </aop:config>
              <tx:advice id="txAdvice" transaction-manager="trasactionManager">
                   <tx:attributes>
                   <tx:method name="getError*" propagation="REQUIRES_NEW" read-only="true"/>
                   <tx:method name="save*" propagation="REQUIRED" rollback-for="com.myCompany.subscription.exception.SubscriptionServiceException"/>
                   <tx:method name="chargeAmount*" propagation="REQUIRED"/>
                   <tx:method name="insert*" propagation="REQUIRED"/>
                   <tx:method name="update*" propagation="REQUIRED"/>
                   <tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
                   <tx:method name="*" propagation="SUPPORTS" read-only="true"/>
              </tx:attributes>
              </tx:advice>
              <!-- Services Started -->
              <bean id="generalDao" class="com.myCompany.subscription.services.dao.GeneralDao">
                   <property name="entityManagerFactory" ref="entityManagerFactory"></property>
              </bean>
              <bean id="logUtil" class="com.myCompany.subscription.services.util.LogUtil" init-method="initialize">
                   <property name="generalDao" ref="generalDao"/>
              </bean>
              <bean id="chargingMsgingClient" class="com.myCompany.subscription.services.client.SubscriptionJMSClient">
                   <property name="logUtil" ref="logUtil"></property>
                   <property name="properties" ref="chrgingProperties"></property>
                   <property name="connectionFactoryName" value="ConnectionFactory"></property>
                   <property name="topicName" value="topic/myCompanyChargingTopic"></property>
              </bean>
              <bean id="messagingJMSClient" class="com.myCompany.subscription.services.client.MessagingJMSClient">
                   <property name="logUtil" ref="logUtil"></property>
                   <property name="properties" ref="msgingProperties"></property>
                   <property name="connectionFactoryName" value="ConnectionFactory"></property>
                   <property name="topicName" value="topic/TempTopic"></property>
              </bean>
              <bean id="subscriptionParams" class="com.myCompany.subscription.services.config.model.SubscriptionServiceParams">
              </bean>
              <bean id="subscriptionConfigService" class="com.myCompany.subscription.services.config.SubscriptionConfigService" init-method="initialize" >
                   <property name="generalDao" ref="generalDao"></property>
                   <property name="paramType" value="MESG_GW"></property>
                   <property name="paramGroup" value="MESG_GW"></property>
                   <property name="msgUserName" value="MSG_USERNAME"></property>
                   <property name="msgUserPassword" value="MSG_PASSWORD"></property>
                   <property name="msgSourceMsisdn" value="MSG_SOURCE_MSISDN"></property>
                   <property name="messagingUrl" value="MESSAGING_URL"></property>
                   <property name="subscriptionParams" ref="subscriptionParams"></property>
                   <property name="msgAgencyId" value="MSG_AGENCYID"></property>
              </bean>
              <bean id="subServiceManager" class="com.myCompany.subscription.services.impl.SubscriptionServiceManager">
                   <property name="generalDao" ref="generalDao"/>
                   <property name="logUtil" ref="logUtil"></property>
                   <property name="ratingEngineService" ref="ratingEngineService"/>
                   <property name="callbackServiceManager" ref="callbackServiceManager"/>
                   <property name="subMsgingClient" ref="subMsgingClient"/>
                   <property name="chargingMsgingClient" ref="chargingMsgingClient"></property>
              </bean>
              <bean id="ratingEngineService" class="com.myCompany.rating.services.impl.RatingEngineService">
                   <property name="generalDao" ref="generalDao"/>
              </bean>
              <bean id="callbackServiceManager" class="com.myCompany.subscallback.services.impl.SubsCallbackServiceManager">
                   <property name="generalDao" ref="generalDao"/>
              </bean>
              <bean id="subscriptionService" class="com.myCompany.subscription.services.impl.SubscriptionService">
                   <property name="generalDao" ref="generalDao"/>
                   <property name="logUtil" ref="logUtil"></property>
                   <property name="subscriptionParamName" value="SUBSCRIPTION"></property>
                   <property name="subscriptionParamType" value="SUBSCRIPTION"></property>
                   <property name="subscriptionParamGroup" value="PLAN_MASTER_TYPE"></property>
              </bean>
              <bean id="subMsgingClient" class="com.myCompany.subscription.services.client.SubscriptionMessageClient">
                   <property name="logUtil" ref="logUtil"></property>
              </bean>
              <bean id="msgGwClient" class="com.myCompany.subscription.services.client.MessageGatewayClient">
                   <property name="subscriptionParams" ref="subscriptionParams"></property>
                   <property name="logUtil" ref="logUtil"></property>
              </bean>
              <bean id="schedulerService" class="com.myCompany.subscription.services.impl.SubscriptionSchedulerService">
                   <property name="generalDao" ref="generalDao"/>
                   <property name="msgClient" ref="subMsgingClient"></property>
                   <property name="logUtil" ref="logUtil"></property>
                   <property name="msgGwClient" ref="msgGwClient"></property>
                   <property name="subscriptionParams" ref="subscriptionParams"></property>
                   <property name="messagingJMSClient" ref="messagingJMSClient"></property>
                   <property name="subServiceManager" ref="subServiceManager"></property>
              </bean>
              <bean id="schedulerLock" class="com.myCompany.subscription.services.model.SchedulerLock">
              </bean>
    </beans>

    Greetings,
    Your error implies that the classpath for the second deployment might be wrong. This cannot be the package if you are deploying an identical ear file. Can you look at the setup for the second container from the admin to see if there is an RMI connection configured incorrectly? Check your opmn.xml file for port info:
    <port id="rmi" range="12401-12500"/>and check the server using netstat -a to see if the configured port is open for use before starting the OAS.
    -Michael

  • TopLink 10g Cascading Issue

    How can I make the default read behavior of each Entity set to **lazyloading** in TopLink 10g?
    We're using TopLink 10g in an application which is being used by 1000s of customers everyday. I'm also looking to find a good and safe way to migrate from TopLink 10g as there are very few stuffs available about TopLink 10g and those who were using it already migrated to EclipseLink/JPA or TopLink 11g-12g. We also have to do the same, but that will be a long-term goal. Please share your experiences regarding migration from TopLink (10g).
    Although, for now, we need to fix a problem (which would be a quick-fix instead of migrate from TopLink 10g). The problem is; One of the TopLink Entity read also getting (querying) all of its associates (child Entities) which is causing too many unnecessary queries to the database. However, we solved this problem by using `ObjectCopyingPolicy`:
        ObjectCopyingPolicy objCopyingPolicy = new ObjectCopyingPolicy();
        objCopyingPolicy.setShouldResetPrimaryKey(false);
        objCopyingPolicy.cascadePrivateParts();
        someEntity = (SomeEntity) getTopLinkTemplate().copy(getTopLinkTemplate().readById(SomeEntity.class, new Long(someId)), objCopyingPolicy);
    The aforementioned code snippet is one of the resolution to solve such a problem. But, we'd like to solve this problem by configuration (persistence.xml etc.). There is nothing in the documentation, neither I found anything by googling it.
    Please let me know if you would require more details to answer this question.
    Good Day!

    First are you using JPA and a persistence.xml with TopLink (TopLink Essentials was the JPA provider I believe) or are you using native TopLink with a sesssions.xml?  WIthout entity changes to support lazy relationships (such as weaving if using JPA) lazy relationships will only work for collection mappings - but these are already set to default to lazy,  If it is JPA, you can configure your entity mappings to be Lazy through annotations or an orm.xml file and let weaving work on your entities, while if using Sessions.xml, you need to make changes to the entities themselves to support lazy relationships as well as set the mappings to be lazy.  This is called indirection in TopLink, and is described here: Understanding Relationship Mappings
    If you are using JPA and a persistence.xml, the migration to EclipseLink should be fairly easy.  See https://wiki.eclipse.org/EclipseLink/Examples/JPA/Migration/TopLinkEssentials for details
    Otherwise it may require package renaming and ensuring that the project was not using deprecated classes, but still should not be too complex.  Migrating from Native TopLink | EclipseLink 2.4.x Understanding EclipseLink has instructions and details.
    If this is not enough to go on, please give more details on what you have. 
    Best Regards,
    Chris

Maybe you are looking for

  • P6N Diamond - Vista/XP won't install.

    I have Vista Home Premium x64 and I went to install for testing before I registered it.  I then see I can install any version of Vista, so I decide to try Vista Ultimate to see how different it is from Home Premium.  Anyway, the trial period for Ulti

  • Changing the printer cartridges for a HP laserjet 2840

    Having a problem with the wheel not going to the next cartridge...there is a message on the display saying "incorrect yellow" but the yellow cartridge has been taken out and it will not go to the next slot. I am out of warranty and need my printer ca

  • RoboHelp 10 and Visual Studio 2010

    The company I work for is thinking about buying RoboHelp 10 to create an offline user help system for a WPF Ribbon Application being developed in Visual Studio 2010. I have been tasked with finding the recommended output format from RoboHelp 10 AND t

  • Partitioning disk

    With a Mac Mini with Intel processor, I am considering partitioning my hard drive into three parts--one for Mac OSx10.4, one for WinXP Home (using Boot Camp), and one for common data storage. Anyone ever tried this particular configuration? Any advic

  • Premiere can't open the Displacement Map filter saved in AE as a PP file. Says DM filter is missing.

    Premiere can't open the Displacement Map filter saved in AE as a PP file. Says DM filter is missing. Also get a message that the format of the AE file does not match the sequence. Asks me to keep existing settings or match sequence - neither way work