Announcement Announcement Module
Collapse
No announcement yet.
Different results in a hql queries between Web App & JUnit Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Different results in a hql queries between Web App & JUnit

    Hello, I have a problem using hibernate and spring in a web application.

    Firts I will tell you some information about my configuration:


    Hibernate-Version: 3.2.5.ga


    When I execute a hql query like this: "From Programa p where p.id = 1"

    Hibernate uses the setters and the unparametrized constructor to obtain the Object "Programa".

    If I'm using the web application, when hibernate is buiding the "Programa" object it does delete's and inserts's of my "relacio_indicadors" and "valor_exercici" relationship.

    But if i'm using a JUnit test this troubles doesn't occurs.

    What's the differents between JUnit Tests and Web Application. What's the problem with this configuration?

    I thought than in some setter i modified the object, but if these happends it will occurs in a JUnit test too, or no?

    Thanks.

    My best regards.

    Oriol Aguilar.

  • #2
    The difference between a JUnit test and the application itself can be small, but on the other hand it can be a huge difference as well, transaction management is sometimes significantly different.

    You will have to provide more information, such as context files and some code etc.

    Cheers

    G

    Comment


    • #3
      This is the information:

      Hibernate-Version: 3.2.5.ga

      Mapping documents:

      Programes

      <hibernate-mapping>
      <class table="PROGRAMES" name="net.sabadell.programes.model.Programa">
      <id name="id">
      <generator class="native"/>
      </id>
      <version unsaved-value="negative" access="field" name="version"/>
      <many-to-one lazy="false" name="area"/>
      <many-to-one lazy="false" name="servei"/>
      <property name="descripcio"/>
      <property name="estat"/>
      <set table="LINIES_ACTUACIO" optimistic-lock="false" access="field" lazy="false" cascade="all" name="liniesActuacio">
      <key column="ID_PROGRAMA"/>
      <composite-element class="net.sabadell.programes.model.LiniaActuacio" >
      <parent name="programa"/>
      <many-to-one lazy="false" name="exercici"/>
      <property name="nom" not-null="true" length="800"/>
      <property name="dataAlta" not-null="true" access="field"/>
      <property name="dataBaixa" access="field"/>
      </composite-element>
      </set>
      <set table="OBJECTIUS" optimistic-lock="false" access="field" lazy="false" cascade="all" name="objectius">
      <key column="ID_PROGRAMA"/>
      <composite-element class="net.sabadell.programes.model.Objectiu">
      <parent name="programa"/>
      <many-to-one lazy="false" name="exercici"/>
      <property name="nom" not-null="true" length="800"/>
      <property name="dataAlta" not-null="true" access="field"/>
      <property name="dataBaixa" access="field"/>
      </composite-element>
      </set>
      <set table="RELACIO_INDICADORS" optimistic-lock="false" access="field" lazy="false" cascade="all" name="indicadors">
      <key column="ID_PROGRAMA"/>
      <composite-element class="net.sabadell.programes.model.RelacioProgram aIndicador">
      <parent name="programa"/>
      <many-to-one lazy="false" name="indicador"/>
      </composite-element>
      </set>
      <set table="PROGRAMES_USUARIS" optimistic-lock="false" access="field" lazy="false" cascade="all" name="usuaris">
      <key column="ID_PROGRAMA"/>
      <many-to-many column="ID_USUARI" class="net.sabadell.programes.model.Usuari"/>
      </set>
      <property name="tipusPrograma"/>
      <set table="ACOMPLIMENTS" optimistic-lock="false" access="field" lazy="false" cascade="all" name="acompliments">
      <key column="ID_PROGRAMA"/>
      <composite-element class="net.sabadell.programes.model.Acompliment">
      <parent name="programa"/>
      <many-to-one lazy="false" name="exercici"/>
      <property name="nom"/>
      <property name="dataAlta" not-null="true" access="field"/>
      <property name="dataBaixa" access="field"/>
      </composite-element>
      </set>
      <property name="nom" not-null="true" length="80" unique="true"/>
      <property name="dataAlta" not-null="true" access="field"/>
      <property name="dataBaixa" access="field"/>
      </class>
      </hibernate-mapping>

      Indicador

      <hibernate-mapping>
      <class table="INDICADORS" name="net.sabadell.programes.model.Indicador">
      <id name="id">
      <generator class="native"/>
      </id>
      <version unsaved-value="negative" access="field" name="version"/>
      <property name="unitat"/>
      <property name="tipusExercici"/>
      <set table="VALOR_EXERCICI" optimistic-lock="false" access="field" lazy="false" cascade="all" name="valorsExercici">
      <key column="ID_INDICADOR"/>
      <composite-element class="net.sabadell.programes.model.ValorExercici" >
      <parent name="indicador"/>
      <many-to-one lazy="false" name="exercici"/>
      <property name="valorPrevisio"/>
      <property name="valorReal"/>
      <property name="dataAlta" not-null="true" access="field"/>
      <property name="dataBaixa" access="field"/>
      </composite-element>
      </set>
      <property name="estat"/>
      <property name="nom" not-null="true" length="80"/>
      <property name="decimalNum"/>
      <property name="dataAlta" not-null="true" access="field"/>
      <property name="dataBaixa" access="field"/>
      </class>
      </hibernate-mapping>

      Configuration:

      <!--
      - Application context definition for MagatzemsBenestar.
      -->
      <beans>

      <!-- ========================= RESOURCE DEFINITIONS ========================= -->

      <!-- Local C3P0 DataSource that works in any environment -->
      <!-- See JPetStore for an example of using Apache Commons DBCP as alternative -->
      <!-- (Both DataSource implementations have a "close" method to be called on shutdown) -->
      <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
      <property name="driverClass" value="${jdbc.driverClassName}"/>
      <property name="jdbcUrl" value="${jdbc.url}"/>
      <property name="user" value="${jdbc.username}"/>
      <property name="password" value="${jdbc.password}"/>
      <property name="minPoolSize" value="5"/>
      <property name="maxPoolSize" value="20"/>
      <property name="loginTimeout" value="300"/>
      <property name="maxIdleTime" value="3000"/>
      <property name="maxStatements" value="50"/>
      </bean>

      <!-- Hibernate SessionFactory -->

      <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
      <property name="dataSource" ref="dataSource"/>
      <property name="mappingLocations">
      <value>classpath*:/net/sabadell/programes/model/*.hbm.xml</value>
      </property>
      <property name="hibernateProperties">
      <props>
      <prop key="hibernate.dialect">${hibernate.dialect}</prop>
      <prop key="hibernate.show_sql">true</prop>
      <prop key="hibernate.generate_statistics">false</prop>
      <prop key="hibernate.max_fetch_depth">3</prop>
      </props>
      </property>
      <property name="namingStrategy">
      <bean class="org.hibernate.cfg.ImprovedNamingStrategy"/>
      </property>
      <property name="eventListeners">
      <map>
      <entry key="merge">
      <bean class="org.springframework.orm.hibernate3.support. IdTransferringMergeEventListener"/>
      </entry>
      </map>
      </property>
      </bean>

      <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
      <bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
      <property name="sessionFactory" ref="sessionFactory"/>
      </bean>

      <!-- Transaction manager that delegates to JTA (for a transactional JNDI DataSource) -->
      <!--
      <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTran sactionManager"/>
      -->


      <!-- ========================= BUSINESS OBJECT DEFINITIONS ========================= -->

      <!--
      - Transactional proxy for Pack Escoles's central data access object.
      -
      - Defines specific transaction attributes with "readOnly" markers,
      - which is an optimization that is particularly valuable with Hibernate
      - (to suppress unnecessary flush attempts for read-only operations).
      -
      - Note that in a real-life app with multiple transaction proxies,
      - you will probably want to use parent and child bean definitions
      - as described in the manual, to reduce duplication.
      -->
      <bean id="TxFactory" abstract="true" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
      <property name="transactionManager" ref="transactionManager"/>
      <property name="transactionAttributes">
      <props>
      <prop key="get*">PROPAGATION_REQUIRED</prop>
      <prop key="find*">PROPAGATION_REQUIRED</prop>
      <prop key="load*">PROPAGATION_REQUIRED</prop>
      <prop key="store*">PROPAGATION_REQUIRED</prop>
      <prop key="execUpdate*">PROPAGATION_REQUIRED</prop>
      <prop key="delete*">PROPAGATION_REQUIRED</prop>
      </props>
      </property>
      </bean>

      <!--
      - Pack Escoles's central data access object: Hibernate implementation.
      -->
      <bean id="programessabadelldao" parent="TxFactory">
      <property name="target">
      <bean class="net.sabadell.programes.model.extra.Programe sSabadellDaoImpl">
      <property name="sessionFactory"><ref bean="sessionFactory"/></property>
      </bean>
      </property>
      </bean>



      <!-- Hibernate 3.0's JMX statistics service -->
      <!-- Implements the StatisticsServiceMBean management interface -->
      <bean name="programessabadell:type=HibernateStatistics" class="org.hibernate.jmx.StatisticsService">
      <property name="sessionFactory" ref="sessionFactory"/>
      </bean>

      </beans>

      Comment

      Working...
      X