[jboss-user] [JBoss Seam] - Re: How to Extend Persistence Context Programatically

bravefencer do-not-reply at jboss.com
Tue Oct 2 03:18:23 EDT 2007


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>

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4090501#4090501

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4090501



More information about the jboss-user mailing list