1 2 Previous Next 21 Replies Latest reply on Oct 2, 2007 4:28 AM by bravefencer Go to original post
      • 15. Re: How to Extend Persistence Context Programatically
        monkeyden

        You can't inject something if you don't know the name. If you have to determine the name at runtime, you'll have to do it inline.

        <core:managed-persistence-context name="myManagername" auto-create="true" persistence-unit-jndi-name="java:/myjndiname">
        </core:managed-persistence-context>



        public void someMethod(){
         String emName = getEMName();
         EntityManager em = (EntityManager)Component.getInstance(emName, true);
        ...
         //do some work
        }
        




        • 16. Re: How to Extend Persistence Context Programatically
          monkeyden

          Actually, if auto-create=true, you don't need the true parameter, but getEMName() would return the String "myManagername" or any other EM name you have configured in components.xml.

          • 17. Re: How to Extend Persistence Context Programatically
            bravefencer

            yes. thats exact what i'am doing, but with more than on EntityManager defined in the corresponding xml files, and it works. Thats not the problem.
            The Problem that the Persistence context seems not to be extended. I get some data sets over the EntityManager, show them in a datatable, use Dataselection Model, but i don't get the correct reference to the selected data set in the table.

            • 18. Re: How to Extend Persistence Context Programatically
              pmuir

              I really doubt your datamodelselection has anything to do with whether the persistence context is extended or not. Why don't you actually post your code and the problem you have rather than plucking solutions out of thin air?

              • 19. Re: How to Extend Persistence Context Programatically
                bravefencer

                but if i extend the context with @PersistenceContext(... type=PersistenceContextType.EXTENDED) Annotation, the Dataselectionmodel works :)
                So i think, its because the Context is not extend, if i do it the other way.

                Anyway, i will post my code tomorrow. It would be very nice if i can get a Solution.

                • 20. Re: How to Extend Persistence Context Programatically
                  bravefencer

                  so here is my code:

                  @Stateful
                  @Scope(ScopeType.SESSION)
                  @Name("SessionObjektAuswahl")
                  public class SessionObjektAuswahl implements ISessionObjektAuswahl{
                  
                  
                   @DataModel
                   private List<KioskPC> kioskPCListe;
                  
                   @DataModelSelection
                   @Out(required=false)
                   private KioskPC kiosk;
                  
                   @Out(required=false)
                   private KioskPC kiosk2;
                  
                   @In(required=false)
                   private String DBname;
                  
                  
                  
                  
                   EntityManager em;
                  
                   @Logger
                   private Log log;
                  
                   private boolean toMitarbeiterAuswahl;
                  
                   @In(required=false)
                   @Out(required=false)
                   private boolean toAnwesenheit;
                  
                  
                   @Create
                   @Factory("kioskPCListe")
                   public String retrieveAllKioskPCEintraege() {
                  
                   initialize();
                   KioskPCAction kioskAction = new KioskPCAction();
                   kioskPCListe = kioskAction.getAllFromDB(em);
                  
                   return null;
                   }
                  
                   private void select(){
                  
                   }
                  
                  
                  
                   private void clearSelected(){
                   kiosk = null;
                  
                   }
                  
                   @Remove @Destroy
                   public void destroy() {
                   // TODO Auto-generated method stub
                  
                   }
                  
                   public void remove() {
                   // TODO Auto-generated method stub
                  
                   }
                  
                  
                   @Override
                   public void initialize() {
                  
                   em = (EntityManager)Component.getInstance("QMoDISZDB");
                  
                  
                   //setLanguage();
                   }
                  
                  
                  
                   private void setLanguage(){
                   this.titleValueObjektauswahl = Parser.read(
                   "FormObjektAuswahl.titel", sprache);
                   this.buttonValueAlleObjekte = Parser.read(
                   "FormObjektAuswahl.btAlleAuswaehlen", sprache);
                   }
                  
                  
                   @Override
                   public String navigate(String id) {
                  
                   if(kiosk!=null){
                   log.info(kiosk.getObjektKostenstelle());
                   }
                  
                  
                   if(toMitarbeiterAuswahl) {
                  
                   toMitarbeiterAuswahl = false;
                  
                   if(id.equals("startseite")){
                   kiosk2=kiosk;
                   return "mitarbeiterAuswahl";
                   }
                  
                   else if(id.equals("clear")){
                   kiosk2=null;
                   return "nachrichtenUebersicht";
                   }
                   }
                  
                   else if (toAnwesenheit){
                   toAnwesenheit = false;
                   if (id.equals("startseite")){
                   kiosk2=kiosk;
                   return "anwesenheit";
                   }else if(id.equals("clear")) {
                   kiosk2=null;
                   clearSelected();
                   return "startseite";
                   }
                   }
                  
                  // else if (id.equals("anwesenheit")){
                  // toAnwesenheit = true;
                  // return "objektAuswahl";
                  // }
                   else if(id.equals("nachrichtErstellen"))
                   {
                   toMitarbeiterAuswahl=true;
                   return "objektAuswahl";
                   }
                  
                  
                   else if(id.equals("startseite")){
                   kiosk2=kiosk;
                   return "startseite";
                   }
                   else if(id.equals("clear")) {
                   kiosk2=null;
                   clearSelected();
                   return "startseite";
                  
                   }
                  
                   return null;
                  
                  
                   }
                  
                  }



                  components.xml:

                  <core:managed-persistence-context name="QMoDISZDB"
                   auto-create="true" persistence-unit-jndi-name="java:/DBzweiEntityManagerFactory" />



                  persistence.xml:
                  <persistence-unit name="DBzwei">
                   <provider>org.hibernate.ejb.HibernatePersistence</provider>
                   <jta-data-source>java:/DBzweisource</jta-data-source>
                  
                   <properties>
                   <property name="hibernate.hbm2ddl.auto" value="none"/>
                   <property name="hibernate.show_sql" value="true"/>
                   <!-- These are the default for JBoss EJB3, but not for HEM: -->
                   <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
                   <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
                  
                   <property name="jboss.entity.manager.factory.jndi.name" value="java:/DBzweiEntityManagerFactory"/>
                   </properties>
                   </persistence-unit>


                  • 21. Re: How to Extend Persistence Context Programatically
                    bravefencer

                    i have found the failure.

                    The SMPC Scope-Type ist Conversational, but i'am using Scope-Type SESSION for my Session Beans.
                    If i switch to Conversational Scope-Type , then it works.
                    Hope the Applications Behaviour will be achieved..

                    1 2 Previous Next