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