schauder wrote:
Is the second select in a different session? Make sure the transaction of that session startet after the commit of the first session/transaction
To be honest, I thought it would all be in the same session. If I save the routine object (basically that has the relationship) and refresh the page I'm displaying it on, it updates.
Code:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="POSTGRESQL" />
<property name="showSql" value="true" />
<property name="generateDdl" value="true"/>
<property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect"/>
</bean>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.cache.use_query_cache">false</prop>
</props>
</property>
</bean>
Now I am saving the step through my admin interface, when I refresh the routine (routine being the object containing a list of steps) it shows happily (although I'm not doing anything to the routine object, but rather using DWR to retrieve steps, so that the page doesn't refresh).
All DAO's are application beans, which means that they should all be in the same hibernate session?
The problem is when I run: getSteps() it uses a cache and does not call the database, unless it is the first time it runs. The only way I've worked around it, is by manually querying the database and returning a list of steps based on the routine currently being displayed on the page.
As far as I am concerned, hibernate should query the database every time I run myroutine.getSteps(); as it is pointless if it will only reflect the changes when I reload the whole context and it runs it's query for the first and only time...
So in point form:
1. In admin using the same DAO beans, I modify the text of a step and save.
2. I can see the changes in the database and in the list of steps as it's retrieved using javascript and dwr (and not getSteps()) on the routine.
3. When I go to the publicly available page and view said routine, the method getSteps() does not even call the database, but returns a PersistentBag from the first time it was run, rather than actually call the database for updates.
Is there a way to force it to use the database every time I run getSteps()?