Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: performance-problem with loading applicationContext

  1. #11
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    What I usually do is keep a separate set of datasource context files (dsContext.xml, dsTestContext.xml, dsTestHSQLContext.xml, etc) defining only different datasources, under the same bean name. At runtime, in different environments I can load the needed ds context together with the main context.

    This allows you to have structurally different datasources - jndi lookup ds, connection pool ds, simple drivermanager ds, etc.

  2. #12
    Join Date
    Dec 2006
    Posts
    29

    Default

    thanks guys, i almost have it. I integrated a couple of ProxyFactoryBean with LazyInitTargetSources into my configuration and set all my beans to lazy-init=true. That gets the perfomance up to 7 sec. loading time which i would accept. BUT ... i have the following problem now:

    I use HibernateAnnotations to map my domain-classes to the database. Here is an extract from one of that classes:

    Code:
    @Entity 
    @Table(name="S_Benutzer",  
    	uniqueConstraints = {@UniqueConstraint(columnNames={"b_nr"})})
    @org.hibernate.annotations.Table(appliesTo="S_Benutzer", indexes={@Index(name="b_nr", columnNames={"b_nr"})})
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    @AccessType("property")
    @Transactional(propagation=Propagation.MANDATORY, rollbackFor=GeplanException.class)
    public class BenutzerDOM implements Serializable, IBenutzerDOM {
    	private static final long serialVersionUID = 1L;
    	private Long id;
    	private String name;
    	private String vorname;
    	private int art;
    	private String kennung;
    	private String passwort;
    	private int sperre;
    	private int standard;
    		
    	public BenutzerDOM() {}
    
    	@Id 
    	@GeneratedValue(generator="pk_creator")
    	@Column(name="b_nr", nullable=false, unique=true, length=4)
    	public Long getId() {
    		return id;
    	}
    
    	@Basic 
    	@Column(name="b_name", length=200)
    	public String getName() {
    		return name;
    	}
    
    	@Basic
    	@Column(name="b_vname", length=200)
    	public String getVorname() {
    		return vorname;
    	}
    
           .....
    the id-generator called "pk_creator" is a global variable set in a file called "package-info.java". Here it is:

    Code:
    @GenericGenerator(name="pk_creator", strategy = "increment")
    package de.gebitms.geplan.datastructures.data;
    
    import org.hibernate.annotations.GenericGenerator;
    Then i define my sessionFactorys in the Spring-Config:

    Code:
    <!-- Hibernate-Session-Factories -->
    <!-- Abstract Classes -->
    <bean id="abstractSessionFactorySQL" abstract="true" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" 
     	scope="singleton" lazy-init="true">
    	<property name="dataSource" ref="dataSourceProxySQL"/>
    	<property name="hibernateProperties" ref="hibernatePropertiesSQL"/>
    	<property name="annotatedPackages" ref="mappingPackages"/>
    	<property name="annotatedClasses" ref="mappingClasses"/>
    	<property name="exposeTransactionAwareSessionFactory"><value>false</value></property>
    </bean>
    <bean id="abstractSessionFactoryOracle" abstract="true" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" 
    		scope="singleton" lazy-init="true">
    	<property name="dataSource" ref="dataSourceProxyOracle"/>
    	<property name="hibernateProperties" ref="hibernatePropertiesOracle"/>
    	<property name="annotatedPackages" ref="mappingPackages"/>
    	<property name="annotatedClasses" ref="mappingClasses"/>
    	<property name="exposeTransactionAwareSessionFactory"><value>false</value></property>
    </bean>
    <!-- Derived Classes -->
    <bean id="sessionFactorySQL" parent="abstractSessionFactorySQL" lazy-init="true"/>
    <bean id="sessionFactorySQLTest" parent="abstractSessionFactorySQL" lazy-init="true">
    	<property name="dataSource" ref="dataSourceProxySQLTest"/>
    </bean>
    <bean id="sessionFactoryOracle" parent="abstractSessionFactoryOracle" lazy-init="true"/>
    <bean id="sessionFactoryOracleTest" parent="abstractSessionFactoryOracle" lazy-init="true">
    	<property name="dataSource" ref="dataSourceProxyOracleTest"/>
    </bean>
    Where the beans "mappingPackages" and "mappingClasses" point to the following declarations:

    Code:
    <util:list id="mappingClasses">
         <value>de.gebitms.geplan.datastructures.data.BenutzerDOM</value>
    </util:list>
    
    <util:list id="mappingPackages">
    	<value>de.gebitms.geplan.datastructures.data</value>
    </util:list>
    If i start my test i get the following error when i try to load a sessionFactory:

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'sessionFactorySQL' defined in class path resource [de/gebitms/geplan/springwrapper/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown Id.generator: pk_creator
    All of this works fine when i change the initialization-strategy for the above beans sessionFactorySQL, sessionFactorySQLTest, sessionFactoryOracle and sessionFactoryOracleTest to an eager loading (lazy-init=false). But that drops my loading time by a second.

    I mean, i could tolerate this one second, but i still wonder whatīs wrong here. It seems that he doesnīt recognize the mapped Package and the id-generator that is declared there, as soon as i proxy the sessionFactory. Why is that or what am i doing wrong? Or is this a bug?

    Could you clear this up?
    Thanks
    Christoph

  3. #13
    Join Date
    Jul 2005
    Posts
    105

    Default

    Quote Originally Posted by kopinsky View Post
    For me it would be better to keep all 4 datasoures (and sessionFactories) defined in the applicationContext.xml file and decide at runtime which of these should be initialized and which should not.

    So i assume that i have to write my own custom BeanFactoryPostProcessor and edit the configuration after it has been loaded but before the beans are initialized. Right? Is it possible to delete certain bean definitions manually from the configuration and with that preventing them from being initialized? Or did i get this all wrong? Do you know where i can find an example of how this is done (if it is possible at all)?

    Thanks
    Christoph
    If you know the various combinations of data sources and session factories that you want to use for your system, I would recommend breaking each data source and session factory into its own file, rather than trying to define everything in one XML file and trying to convince some of them not to load, else you're quickly going to run into a maintenance nightmare. Use a bean ref context (accessed by a SingletonBeanFactoryLocator) to group the logical combinations of these files together and access via the ID of the bean ref context. You can load the ID in from a system property, external file, etc.

  4. #14
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    I would agree with the previous author. I think this could be really complicated and as you have already seen. I would guess that you are loading a Hibernate object which references your generator, but the generator hasn't been included.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •