Is it possible to set expiry time using Apache Ignite in C++? - c++

I am using the C++ thin client API and I want to have the data deleted from the cache after 5 minutes. I am connecting to ignite through docker and using the persistence storage. In the documentation for the C++ libraries, I cannot find anything relating to "expiry" and I tried adding the expiry option into the config xml file that my docker container reads in, but that didn't seem to work either. I put data into the cache and checked for the data after 5 minutes (I also checked 10, 20, 30 minutes later) and the data was still there.
Here is my config xml file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<!-- Enabling Apache Ignite Persistent Store. -->
<property name="dataStorageConfiguration">
<bean class="org.apache.ignite.configuration.DataStorageConfiguration">
<property name="defaultDataRegionConfiguration">
<bean class="org.apache.ignite.configuration.DataRegionConfiguration">
<property name="persistenceEnabled" value="true"/>
<property name="name" value="Default_Region" />
</bean>
</property>
</bean>
</property>
<property name="discoverySpi">
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
<property name="ipFinder">
<!-- Uncomment static IP finder to enable static-based discovery of initial nodes. -->
<!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">-->
<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
<property name="addresses">
<list>
<!-- In distributed environment, replace with actual host IP address. -->
<value>127.0.0.1:47500..47502</value>
</list>
</property>
</bean>
</property>
</bean>
</property>
</bean>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="expiryPolicyFactory">
<bean class="javax.cache.expiry.CreatedExpiryPolicy" factory-method="factoryOf">
<constructor-arg>
<bean class="javax.cache.expiry.Duration">
<constructor-arg value="MINUTES"/>
<constructor-arg value="5"/>
</bean>
</constructor-arg>
</bean>
</property>
</bean>
</beans>

Yes, the c++ thin client doesn't support this feature at the moment.
I think you could either define a cache with expiration completely on the server-side or to define only a cache template https://apacheignite.readme.io/docs/cache-template with expiry policy and use it from a client.

Related

Apache Ignite autoscaling in AWS (linux)

Currently we host Apache Ignite node in AWS using Apache Ignite Image with 16 RAM.
We want to dynamically add new nodes while load on cache increases.
For this purpose we need to somehow trigger that node will run out of memory soon and we need to add additional node. Is there any way to track that?
I've tried to load cache with random data, cache failed with OutOfMemoryException when java process took over 30-40% of RAM.
Here is default-config.xml from {IGNITE_HOME}\config:
<?xml version="1.0" encoding="UTF-8"?>
...
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="cacheConfiguration">
<list>
<!-- Partitioned cache example configuration (Atomic mode). -->
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="default"/>
<property name="atomicityMode" value="ATOMIC"/>
<property name="backups" value="1"/>
</bean>
</list>
</property>
<!-- Enabling Apache Ignite Persistent Store. -->
<property name="dataStorageConfiguration">
<bean class="org.apache.ignite.configuration.DataStorageConfiguration">
<property name="defaultDataRegionConfiguration">
<bean class="org.apache.ignite.configuration.DataRegionConfiguration">
<property name="persistenceEnabled" value="false"/>
<property name="metricsEnabled" value="true"/>
<property name="maxSize" value="#{10L * 1024 * 1024 * 1024}"/>
</bean>
</property>
</bean>
</property>
<!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
<property name="discoverySpi">
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
<property name="ipFinder">
<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.s3.TcpDiscoveryS3IpFinder">
<property name="awsCredentialsProvider" ref="aws.creds"/>
<property name="bucketName" value="dev-apache-ignite"/>
</bean>
</property>
</bean>
</property>
</bean>
<!-- AWS credentials. Provide your access key ID and secret access key. -->
<bean id="aws.creds" class="com.amazonaws.auth.InstanceProfileCredentialsProvider">
<constructor-arg value="false" />
</bean>
</beans>
Sorry if this question was alsready answered in documentation.
Is there any predefined guidelines to configure AWS autoscaling for ignite?
Amount of RAM taken by JVM is not relevant. You will see IgniteOutOfMemoryException when you run out of data region - in your case, 10G.
You may divide DataRegionMetrics.getOffheapUsedSize() by data region size to understand how much runway do you have left.
Then you can probably use GridGain K8S Operator to scale your cluster:
https://www.gridgain.com/docs/latest/installation-guide/operator/how-tos

Servlet filter invoke not on default port [duplicate]

I'm running embedded jetty inside of a spring ioc container. The spring ioc contains also an embedded hsqldb which makes the whole configuration a nice and complete web application development environment (on a single JVM). Now I'm trying to add apache CXF to this environment to make the jetty host not only servlets but also web services.
Unfortunately I'm getting NullPointerException when attempting to access http://127.0.0.1:8080/cxf/* (servlets and static content are served ok). Any idea what's wrong?
2010-09-17 15:37:20,099 [btpool0-1 - /cxf/] DEBUG org.mortbay.log - REQUEST /cxf/ on org.mortbay.jetty.HttpConnection#2d14d18f
2010-09-17 15:37:20,100 [btpool0-1 - /cxf/] DEBUG org.mortbay.log - servlet=cxf-servlet-holder
2010-09-17 15:37:20,100 [btpool0-1 - /cxf/] DEBUG org.mortbay.log - chain=null
2010-09-17 15:37:20,100 [btpool0-1 - /cxf/] DEBUG org.mortbay.log - servelet holder=cxf-servlet-holder
2010-09-17 15:37:20,101 [btpool0-1 - /cxf/] ERROR org.mortbay.log - /cxf/
java.lang.NullPointerException
at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:142)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:179)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:108)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:159)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:367)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
at org.mortbay.jetty.Server.handle(Server.java:281)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:502)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:821)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:208)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:378)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:368)
at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
I'm initializing spring with:
public static void main(String[] args) throws Exception {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[] { "jetty-beans.xml" , "cxf-beans.xml" });
applicationContext.getBean("web-server", Server.class).join();
}
jetty-beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean name="web-server" class="org.mortbay.jetty.Server"
init-method="start">
<property name="connectors">
<list>
<bean class="org.mortbay.jetty.nio.SelectChannelConnector">
<property name="host" value="localhost" />
<property name="port" value="8080" />
</bean>
</list>
</property>
<property name="handlers">
<list>
<ref bean="web-server-context-static" />
<ref bean="web-server-context-servlet" />
<ref bean="web-server-context-cxf" />
</list>
</property>
</bean>
<bean name="web-server-context-static" class="org.mortbay.jetty.servlet.Context">
<property name="contextPath" value="/static" />
<property name="handler">
<bean class="org.mortbay.jetty.handler.ResourceHandler">
<property name="resourceBase" value="static" />
</bean>
</property>
</bean>
<bean name="web-server-context-servlet" class="org.mortbay.jetty.servlet.Context">
<property name="contextPath" value="/servlet" />
<property name="handler">
<bean class="org.mortbay.jetty.servlet.ServletHandler">
<property name="servlets">
<list>
<bean class="org.mortbay.jetty.servlet.ServletHolder">
<property name="name" value="servlet-holder" />
<property name="servlet">
<bean class="test.TestServlet" />
</property>
</bean>
</list>
</property>
<property name="servletMappings">
<list>
<bean class="org.mortbay.jetty.servlet.ServletMapping">
<property name="servletName" value="servlet-holder" />
<property name="pathSpec" value="/*" />
</bean>
</list>
</property>
</bean>
</property>
</bean>
<bean name="web-server-context-cxf" class="org.mortbay.jetty.servlet.Context">
<property name="contextPath" value="/cxf" />
<property name="handler">
<bean class="org.mortbay.jetty.servlet.ServletHandler">
<property name="servlets">
<list>
<bean class="org.mortbay.jetty.servlet.ServletHolder">
<property name="name" value="cxf-servlet-holder" />
<property name="servlet">
<bean class="org.apache.cxf.transport.servlet.CXFServlet">
</bean>
</property>
</bean>
</list>
</property>
<property name="servletMappings">
<list>
<bean class="org.mortbay.jetty.servlet.ServletMapping">
<property name="servletName" value="cxf-servlet-holder" />
<property name="pathSpec" value="/*" />
</bean>
</list>
</property>
</bean>
</property>
</bean>
</beans>
cxf-beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean id="test-ws-impl" class="test.TestWSImpl" />
<jaxws:endpoint id="test-ws-endpoint" implementor="#test-ws-impl"
address="/testWS" />
</beans>
classpath:
activation-1.1.jar
commons-logging-1.1.1.jar
cxf-2.2.10.jar
jaxb-api-2.1.jar
jaxb-impl-2.1.13.jar
jcl-over-slf4j-1.6.1.jar
jetty-6.1.3.jar
jetty-annotations-6.1.3.jar
jetty-util-6.1.3.jar
log4j-1.2.16.jar
neethi-2.0.4.jar
org.springframework.aop-3.0.3.RELEASE.jar
org.springframework.asm-3.0.3.RELEASE.jar
org.springframework.beans-3.0.3.RELEASE.jar
org.springframework.context-3.0.3.RELEASE.jar
org.springframework.context.support-3.0.3.RELEASE.jar
org.springframework.core-3.0.3.RELEASE.jar
org.springframework.expression-3.0.3.RELEASE.jar
servlet-api-2.5-6.1.3.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
wsdl4j-1.6.2.jar
XmlSchema-1.4.5.jar
TestWSImpl.java:
package test;
import javax.jws.WebService;
#WebService(endpointInterface = "test.TestWSInterface")
public class TestWSImpl implements TestWSInterface {
#Override
public String doTest(String testSubject) {
return "successfully tested:" + testSubject;
}
}
TestWSInterface.java
package test;
import javax.jws.WebParam;
import javax.jws.WebService;
#WebService
public interface TestWSInterface {
String doTest(#WebParam String testSubject);
}
I've found out that the above configuration was wrong:
I did not use any WebApplicationContext with has to be initialized prior to the CXFServlet. The simple solution is to use the non-spring version of CXFServlet - it does not require any ApplicationContext (I don't want to create a separate ApplicationContext for the Web Services since I need to have shared DataSource between them) but it has too be initialized (Web Services must be published in the code).
After solving the Context issue I've found out that jetty 6.1 does not initialize the servlet context in proper way, everything works fine after updating to 7.x.
After writing custom WebApplicationContext I was able to use the main/root ApplicationContext as the WebApplicationContext allowing me to use the spring version of CXFServlet with about 6 lines of glue code.

Testing Spring-JPA

I am developping a web application using Spring (3.1.x), JSF 2, JPA 2 (Hibernate Provider) for tomcat 6.x.
I want to test my DAO classes.
In my DAO class: i do this:
#PersistenceContext
private EntityManager entityManager;
In Spring Configuration;
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="OpenPU" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
In persistence.xml
<persistence-unit name="OpenPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>java:comp/env/jdbc/mysql_open</non-jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" />
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.transaction.flush_before_completion" value="true"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
<property name="hibernate.connection.zeroDateTimeBehavior" value="convertToNull"/>
</properties>
</persistence-unit>
It the first time I make test, and when I test I don't want to use the same persistence unit. I heard about dbunit for using xml data, but i don't understand how to change the persistence unit during the test.
Can you help me or give me some example, tutorial.
Thanks you.
Maybe this tutorial will help.
BTW, there is one interesting Spring feature to fit your needs - embedded database support. So, I usually just use following construction to create in-memory H2 db, create schema with schema.sql and fill it with some data from test-data.sql:
<jdbc:embedded-database id="dataSource" type="H2">
<jdbc:script location="classpath:schema.sql"/>
<jdbc:script location="classpath:test-data.sql"/>
</jdbc:embedded-database>
Then you could use this bean as datasource for you EntityManagerFactory bean:
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="dataSource"
p:persistence-xml-location="classpath:META-INF/persistence.xml">
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
<property name="showSql" value="true" />
<!-- other properties -->
</bean>
</property>
<property name="persistenceUnitName" value="OpenPU" />
</bean>
This is very convenient and concise way to create in-memory database for tests with Spring.
(don't forget to add H2 in your classpath)
See documentation for details, chapter "13.8 Embedded database support".

Apache CXF + resource handler with embedded jetty in osgi with spring dm

I'm trying to run an apache cxf endpoint in an equinox osgi environment with jetty 7. I need the endpoint to be on address http://x.x.x.x:8080/ws/endpoint1 and have static resources on the root path http://x.x.x.x:8080/*.
I have a dedicated bundle for this purpose containing the cxf libraries. Spring dynamic modules are part of my target platform.
After some research I tried to start the jetty webserver in my spring application context.
<bean id="Server" class="org.eclipse.jetty.server.Server"
init-method="start" destroy-method="stop">
<property name="connectors">
<list>
<bean id="Connector" class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<property name="port" value="8080" />
</bean>
</list>
</property>
<property name="handler">
<bean id="handlers" class="org.eclipse.jetty.server.handler.HandlerList">
<property name="handlers">
<list>
<bean class="org.eclipse.jetty.server.handler.ResourceHandler">
<property name="directoriesListed" value="true" />
<property name="welcomeFiles">
<list>
<value>index.html</value>
</list>
</property>
<property name="resourceBase" value="./someDir" />
</bean>
<ref bean="web-service-cxf" />
<bean class="org.eclipse.jetty.server.handler.DefaultHandler" />
</list>
</property>
</bean>
</property>
</bean>
<bean name="web-service-cxf" class="org.eclipse.jetty.servlet.ServletContextHandler">
<property name="contextPath" value="/ws" />
<property name="handler">
<bean class="org.eclipse.jetty.servlet.ServletHandler">
<property name="servlets">
<list>
<bean class="org.eclipse.jetty.servlet.ServletHolder">
<property name="name" value="cxf-servlet-holder" />
<property name="servlet">
<bean class="org.apache.cxf.transport.servlet.CXFServlet">
</bean>
</property>
</bean>
</list>
</property>
<property name="servletMappings">
<list>
<bean class="org.eclipse.jetty.servlet.ServletMapping">
<property name="servletName" value="cxf-servlet-holder" />
<property name="pathSpec" value="/*" />
</bean>
</list>
</property>
</bean>
</property>
</bean>
My WebService Endpoint is declared with:
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean id="someService" class="abc.xyz.SomeClass" />
<jaxws:endpoint id="endpointId" implementor="#someBean"
address="/endpoint1">
</jaxws:endpoint>
Unfortunatly this is not working. I can reach the static resources, but not the webservice.
The log says, the WebService is published under address /endpoint1. No warnings, no exceptions.
When I change the address of the webservice to its full url
<bean id="someService" class="abc.xyz.SomeClass" />
<jaxws:endpoint id="endpointId" implementor="#someBean"
address="http://x.x.x.x:8080/ws/endpoint1">
</jaxws:endpoint>
the webservice works fine, but the static ressources are not available any more.
Is it possible with a configuration like this to publish an endpoint to a running jetty with relative address? Or am I totally wrong? Most examples I found on the web use a web.xml, but I'm not working with an application server like tomcat and need the application to be a standalone eclipse app.
Spend the whole last two nights on this, any help is highly appreciated.
Kind regards,
Onno
There are sooo many samples here. U shud be able to find what u r looking for
http://svn.apache.org/repos/asf/cxf/branches/2.4.x-fixes/distribution/src/main/release/samples

During Spring unit test, data written to db but test not seeing the data

I wrote a test case that extends AbstractTransactionalJUnit4SpringContextTests. The single test case I've written creates an instance of class User and attempts to write it to the database using Hibernate. The test code then uses SimpleJdbcTemplate to execute a simple select count(*) from the user table to determine if the user was persisted to the database or not. The test always fails though. I was suspect because in the Spring controller I wrote, the ability to save an instance of User to the db is successful.
So I added the Rollback annotation to the unit test and sure enough, the data is written to the database since I can even see it in the appropriate table -- the transaction isn't rolled back when the test case is finished.
Here's my test case:
#ContextConfiguration(locations = {
"classpath:context-daos.xml",
"classpath:context-dataSource.xml",
"classpath:context-hibernate.xml"})
public class UserDaoTest extends AbstractTransactionalJUnit4SpringContextTests {
#Autowired
private UserDao userDao;
#Test
#Rollback(false)
public void teseCreateUser() {
try {
UserModel user = randomUser();
String username = user.getUserName();
long id = userDao.create(user);
String query = "select count(*) from public.usr where usr_name = '%s'";
long count = simpleJdbcTemplate.queryForLong(String.format(query, username));
Assert.assertEquals("User with username should be in the db", 1, count);
}
catch (Exception e) {
e.printStackTrace();
Assert.assertNull("testCreateUser: " + e.getMessage());
}
}
}
I think I was remiss by not adding the configuration files.
context-hibernate.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd>
<bean id="namingStrategy" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
<property name="staticField">
<value>org.hibernate.cfg.ImprovedNamingStrategy.INSTANCE</value>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" destroy-method="destroy" scope="singleton">
<property name="namingStrategy">
<ref bean="namingStrategy"/>
</property>
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>com/company/model/usr.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.use_sql_comments">true</prop>
<prop key="hibernate.query.substitutions">yes 'Y', no 'N'</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_minimal_puts">false</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
<property name="nestedTransactionAllowed" value="false" />
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref local="transactionManager"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="create">PROPAGATION_REQUIRED</prop>
<prop key="delete">PROPAGATION_REQUIRED</prop>
<prop key="update">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_SUPPORTS,readOnly</prop>
</props>
</property>
</bean>
</beans>
context-dataSource.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="org.postgresql.Driver" />
<property name="jdbcUrl" value="jdbc\:postgresql\://localhost:5432/company_dev" />
<property name="user" value="postgres" />
<property name="password" value="postgres" />
</bean>
</beans>
context-daos.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="extendedFinderNamingStrategy" class="com.company.dao.finder.impl.ExtendedFinderNamingStrategy"/>
<bean id="finderIntroductionAdvisor" class="com.company.dao.finder.impl.FinderIntroductionAdvisor"/>
<bean id="abstractDaoTarget" class="com.company.dao.impl.GenericDaoHibernateImpl" abstract="true" depends-on="sessionFactory">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
<property name="namingStrategy">
<ref bean="extendedFinderNamingStrategy"/>
</property>
</bean>
<bean id="abstractDao" class="org.springframework.aop.framework.ProxyFactoryBean" abstract="true">
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
<value>finderIntroductionAdvisor</value>
</list>
</property>
</bean>
<bean id="userDao" parent="abstractDao">
<property name="proxyInterfaces">
<value>com.company.dao.UserDao</value>
</property>
<property name="target">
<bean parent="abstractDaoTarget">
<constructor-arg>
<value>com.company.model.UserModel</value>
</constructor-arg>
</bean>
</property>
</bean>
</beans>
Some of this I've inherited from someone else. I wouldn't have used the proxying that is going on here because I'm not sure it's needed but this is what I'm working with.
Any help much appreciated.
IIRC, Hibernate (and other O/R mappers) delay the database INSERT and UPDATE statements until the transaction commit. The SELECT then does not see the data, as it is not yet written. Try explicitly requesting a session flush.
See also the documentation for an explanation and example:
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/objectstate.html#objectstate-flushing
Doesn't transactionInterceptor automatically commits?
http://www.docjar.com/html/api/org/springframework/transaction/interceptor/TransactionInterceptor.java.html
Line 117:
commitTransactionAfterReturning(txInfo);
By default the flush mode should be auto, so there should be an implicit flush when commit is performed. I have the same problem and had to solve it by manually calling flush. That is very unsatisfying because my existing code depends on auto-flush before migrating to Spring transation manager. I wish there is a way to tell org.springframework.orm.hibernate3.HibernateTransactionManager to flush after commit.