I am using Hibernate/JPA with mySQL, and because of legacy reasons createNativeQuery at one point. The application works with different servers using the same database, so it should do no caching at all but always show the most recent result. I simulate other servers by changing a value manually in a database-editor, but after a change it always gives old results.
As far as I know I should disable any 2nd level caching (not very important because I do not use any ORM-objects), clear() any 1st level caching, and disable mysql query caching (is already done on database level). Where do I fail, or what do I forget? It drives me crazy.
init(): start of the servlet
entityFactory = Persistence.createEntityManagerFactory("persistence-id");
getEntityManager(): start of each request
destroyEntityManager(); // just in case
entityFactory.getCache().evictAll();
entityManager = entityFactory.createEntityManager();
entityManager.setProperty("javax.persistence.cache.storeMode",
CacheStoreMode.BYPASS);
entityManager.clear(); // just in case
destroyEntityManager(): end of each request
if (entityManager != null) {
if (entityManager.getTransaction().isActive()) {
entityManager.flush();
entityManager.getTransaction().commit();
}
entityManager.clear();
if (entityManager.isOpen()) {
entityManager.close();
}
entityManager = null;
}
destroy(): end of servlet
destroyEntityManager();
if (entityFactory != null) {
entityFactory.close();
}
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="WallMountBackOffice-PU">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>...</class>
<class>...</class>
<properties>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost/ourschema" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password" value="" />
<property name="hibernate.connection.pool_size" value="10" />
<property name="hibernate.connection.autocommit" value="false" />
<property name="hibernate.connection.release_mode" value="on_close" />
<property name="dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.cache.use_second_level_cache"
value="false" />
<property name="hibernate.cache.use_query_cache" value="false" />
<property name="javax.persistence.sharedCache.mode" value="NONE" />
<property name="org.hibernate.cacheable" value="false" />
</properties>
</persistence-unit>
The code which does the 'select ...':
...
Query jpaQuery = entityManager.createQuery(query);
entityManager.getTransaction().begin();
jpaQuery.executeUpdate();
entityManager.getTransaction().commit();
In first line, there is a mistake, it must be "BYPASS" not "REFRESH", as following:
query.setHint("javax.persistence.cache.retrieveMode", "BYPASS");
And using the JPA enums instead of string literals is recommended, so it will be:
query.setHint(QueryHints.CACHE_RETRIEVE_MODE, CacheRetrieveMode.BYPASS);
query.setHint(QueryHints.CACHE_STORE_MODE, CacheStoreMode.REFRESH);
You can use setHint() storeMode or retrieveMode method. If you are trying to retrieve the record, use retrieveMode with BYPASS.
For Hibernate
query.setHint("javax.persistence.cache.storeMode", "REFRESH");
query.setHint("javax.persistence.cache.retrieveMode", "REFRESH");
For EclipseLink.
query.setHint("javax.persistence.cache.storeMode", "REFRESH");
query.setHint("javax.persistence.cache.retrieveMode", "REFRESH");
JPA 2.0 Specification
public enum CacheRetrieveMode {
/**
* Read entity data from the cache: this is
* the default behavior.
*/
USE,
/**
* Bypass the cache: get data directly from
* the database.
*/
BYPASS
}
public enum CacheStoreMode {
/**
* Insert/update entity data into cache when read
* from database and when committed into database:
* this is the default behavior. Does not force refresh
* of already cached items when reading from database.
*/
USE,
/**
* Don't insert into cache.
*/
BYPASS,
/**
* Insert/update entity data into cache when read
* from database and when committed into database:
* Forces refresh of cache for items read from database.
*/
REFRESH
}
Related
As seen in below code in step1 I'm reading users.xml and writing to database now in step2 I'm reading from userdetails.xml and writing to database but I need step1 auto generated key of tbl_user for step2. How Can I do that?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
<import resource="../config/context.xml" />
<import resource="../config/database.xml" />
<bean id="xmlItemReader1" class="org.springframework.batch.item.xml.StaxEventItemReader">
<property name="resource" value="file:xml/outputs/users.xml" />
<property name="fragmentRootElementName" value="user" />
<property name="unmarshaller" ref="userUnmarshaller"/>
</bean>
<bean id="xmlItemReader2" class="org.springframework.batch.item.xml.StaxEventItemReader">
<property name="resource" value="file:xml/outputs/userdetails.xml" />
<property name="fragmentRootElementName" value="userdetail" />
<property name="unmarshaller" ref="userUnmarshaller"/>
</bean>
<bean id="itemProcessor1" class="com.qmetry.recovery.mapper.UserItemProcessor" />
<bean id="itemProcessor2" class="com.qmetry.recovery.mapper.UserDetailItemProcessor" />
<job id="testJob2" xmlns="http://www.springframework.org/schema/batch">
<step id="step2_1">
<tasklet transaction-manager="transactionManager">
<chunk reader="xmlItemReader1" writer="databaseItemWriter1" processor="itemProcessor1"
commit-interval="100" />
</tasklet>
<listeners>
<listener ref="testListener" />
</listeners>
</step>
<step id="step2_2">
<tasklet transaction-manager="transactionManager">
<chunk reader="xmlItemReader2" writer="databaseItemWriter2" processor="itemProcessor1"
commit-interval="100" />
</tasklet>
</step>
</job>
<bean id="testListener" class="com.qmetry.recovery.mapper.TestListener" scope="step" />
<bean id="databaseItemWriter1" class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<property name="dataSource" ref="dataSource" />
<property name="sql">
<value>
<![CDATA[
insert into TBL_USER(USERNAME,EMAILID)
values (?, ?)
]]>
</value>
</property>
<!--We need a custom setter to handle the conversion between Jodatime LocalDate and MySQL DATE BeanPropertyItemSqlParameterSourceProvider-->
<property name="itemPreparedStatementSetter">
<bean class="com.qmetry.recovery.mapper.UserItemPreparedStatementSetter"/>
</property>
</bean>
<bean id="databaseItemWriter2" class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<property name="dataSource" ref="dataSource" />
<property name="sql">
<value>
<![CDATA[
insert into TBL_USERDETAIL(USERID,CONTACT)
values (?, ?)
]]>
</value>
</property>
<!--We need a custom setter to handle the conversion between Jodatime LocalDate and MySQL DATE BeanPropertyItemSqlParameterSourceProvider-->
<property name="itemPreparedStatementSetter">
<bean class="com.qmetry.recovery.mapper.UserDetailItemPreparedStatementSetter"/>
</property>
</bean>
users.xml
<?xml version="1.0" encoding="UTF-8"?><users>
<user>
<userId>1</userId>
<userName>Taher</userName>
<emailId>taher.tinwala#hotmail.com</emailId>
</user>
</users>
userdetails.xml
<?xml version="1.0" encoding="UTF-8"?><userdetails>
<userdetail>
<userDetailId>1</userDetailId>
<userId__TblUser>1</userId__TblUser>
<contact>1111111111</contact>
</userdetail>
<userdetail>
<userDetailId>2</userDetailId>
<userId__TblUser>1</userId__TblUser>
<contact>2222222222</contact>
</userdetail>
<userdetail>
<userDetailId>4</userDetailId>
<userId__TblUser>1</userId__TblUser>
<contact>4444444444</contact>
</userdetail>
</userdetails>
You need to pass data to a future step. For explantory documentation see http://docs.spring.io/spring-batch/trunk/reference/html/patterns.html#passingDataToFutureSteps
I have implemented the example from the documentation and adjusted it to your configuration with some assumptions here and there.
During the read (or the write, it depends when you get the data that you want to pass) in step 1 you need to store the data in the StepExecution. Add to your xmlItemReader the following:
public class YourItemReader implements ItemReader<Object>
private StepExecution stepExecution;
public void read(Object item) throws Exception {
// ...
ExecutionContext stepContext = this.stepExecution.getExecutionContext();
stepContext.put("tbl_user", someObject);
}
#BeforeStep
public void saveStepExecution(StepExecution stepExecution) {
this.stepExecution = stepExecution;
}
Your xml will look like this:
<step id="step2_1">
<tasklet transaction-manager="transactionManager">
<chunk reader="xmlItemReader1" writer="databaseItemWriter1" processor="itemProcessor1" commit-interval="100" />
</tasklet>
<listeners>
<listener ref="testListener" />
<listener ref="promotionListener"/>
</listeners>
</step>
Add the promotionListener bean:
<beans:bean id="promotionListener" class="org.springframework.batch.core.listener.ExecutionContextPromotionListener">
<beans:property name="keys" value="tbl_key"/>
</beans:bean>
And finally you need to retrieve the value in step 2. Again asuming you need it in the reader of step 2 you reader in step 2 needs the following code added:
public class YourItemReader2 implements ItemReader<Object>
private Object someObject;
#BeforeStep
public void retrieveInterstepData(StepExecution stepExecution) {
JobExecution jobExecution = stepExecution.getJobExecution();
ExecutionContext jobContext = jobExecution.getExecutionContext();
this.someObject = jobContext.get("tbl_key");
}
Now you have acces to the value read in step 1.
EDIT - adding some example configuration for an extra read step:
After step 1 add a simple step 2 with the following reader to get the new value from the database
<bean id="itemReader" class="org.springframework.batch.item.database.JdbcCursorItemReader"
scope="step">
<property name="dataSource" ref="dataSource" />
<property name="sql">
<value>
<![CDATA[
YOUR SELECT STATEMENT
]]>
</value>
</property>
<property name="rowMapper" ref="rowMapper" />
</bean>
And a simple rowMapper bean
<bean id="rowMapper" class="exampleRowMapper" />
You will have to write your exampleRowMapper obviously to reflect the data your fetching. For example:
public class ExampleRowMapper implements ParameterizedRowMapper<String> {
#Override
public String mapRow(ResultSet rs, int rowNum) throws SQLException {
return String.valueOf(rs.getString(1));
}
}
In your dummywriter you add the stepexecution and you will store your value in the step execution context.:
public class DummyItemWriter implements ItemWriter<Object> {
private StepExecution stepExecution;
#Override
public void write(List<? extends Object> item) throws Exception {
ExecutionContext stepContext = this.stepExecution.getExecutionContext();
stepContext.put("someKey", someObject);
}
}
And the bean for the writer:
<bean id="savingDummyWriter" class="your.package.DummyItemWriter" />
And wrap the reader and writer in a step.
<step id="step2">
<tasklet>
<chunk reader="itemReader" writer="dummyItemWriter" commit-interval="1" />
</tasklet>
<listeners>
<listener ref="promotionListener"/>
</listeners>
</step>
I am developing a website on TomEE, and I want to use the EclipseLink Query Results Cache (L2) working, but every time I reload my web page, SELECT query is running (checked via general_log of mysql).
My Database entity looks like below:
#Entity(name="item")
#NamedQueries({
#NamedQuery(name="ItemEntity.getAllList",
query="Select distinct itemEntity from mypackage.entity.ItemEntity itemEntity",
hints={
#QueryHint(name="eclipselink.query-results-cache", value="true"),
#QueryHint(name="eclipselink.query-results-cache.size", value="1000"),
#QueryHint(name="eclipselink.query-results-cache.expiry", value="10000"), //10 secs for test but not working
#QueryHint(name="eclipselink.query-results-cache.type", value="FULL")
}
)
})
#org.eclipse.persistence.annotations.Cache(
type= CacheType.FULL,
size=10000,
expiry=60000, // 1 minute for test
coordinationType= CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS
)
public class ItemEntity implements Serializable, Comparable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
#Column(name="name", unique=true, nullable=false)
private String name;
/* getters and setters for fields */
public CompanyEntity(){}
#Override
public int compareTo(Object o) {.......}
}
My persistence.xml looks like below:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="myprojectname-persistence-unit" transaction-type="JTA">
<jta-data-source>myprojectname-mysql-jdbc-jta-resource</jta-data-source>
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<properties>
<property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.MySQLPlatform"/>
<property name="eclipselink.cache.shared.default" value="true"/>
</properties>
</persistence-unit>
</persistence>
I read database table like below:
#Stateful
public class CompanyDao {
#PersistenceContext(unitName = "myprojectname-persistence-unit", type = PersistenceContextType.EXTENDED)
protected EntityManager em;
public List<CompanyEntity> getAllList(){
return this.em.createNamedQuery("ItemEntity.getAllList", ItemEntity.class).getResultList();
}
}
Dependency version details:
TomEE 1.7.2, Java EE6, openJPA 2.4.0, openEJB Java EE API 6.0-6, openEJB core 4.7.2, EclipseLink 2.6.2, MySQL 5.6.23, MySQL connector/J 5.1.38 (Tomcat connection pool)
I've looked at a similar question:
Can't get Eclipselink level 2 cache to work
but it doesn't describe how the OP managed to cache query results.
BTW, the default cache (L2), with em.find(ItemEntity.class, id); is working just fine.
What am I missing? Please help me out.
Solved.
I was using EclipseLink 2.6.2, I downgraded to version 2.4.2, and now Query Results Cache WORKS as expected!
I guess EclipseLink 2.6.x or 2.5.x is not quite compatible with JPA 2.0.x.
It's confusing, because when I use 2.5.x or higher, those still seem to be working, BESIDES the feature of Query Results Cache.
My persistence.xml looks like bellow now, so I can get log output:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="myprojectname-persistence-unit" transaction-type="JTA">
<jta-data-source>myprojectname-mysql-jdbc-jta-resource</jta-data-source>
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<properties>
<property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.MySQLPlatform"/>
<property name="eclipselink.logging.logger" value="JavaLogger"/>
<!-- The warning log of "Problem while registering MBean: java.lang.NullPointerException" did not go away even if I set bellow 2 propertes -->
<!--
<property name="eclipselink.register.dev.mbean" value="false" />
<property name="eclipselink.register.run.mbean" value="false" />
-->
<property name="eclipselink.cache.shared.default" value="true"/>
<property name="eclipselink.logging.parameters" value="true"/>
<property name="eclipselink.logging.timestamp" value="true"/>
<property name="eclipselink.logging.session" value="true"/>
<property name="eclipselink.logging.thread" value="true"/>
<property name="eclipselink.logging.exceptions" value="true"/>
<property name="eclipselink.logging.level" value="FINEST"/>
</properties>
</persistence-unit>
</persistence>
I have a test like the following
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = { "classpath:META-INF/spring/testDataSpringContext.xml" })
#Transactional
#TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
#TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class,
TransactionDbUnitTestExecutionListener.class })
public class AgenceDAOTest {
#Autowired
private AgenceDAO mAgenceDAO;
#Test
#DatabaseSetup(value = "/META-INF/db-test/sampleData.xml", type = DatabaseOperation.REFRESH)
public void listAgences() {
List<AgenceVO> vListeAgences = mAgenceDAO.getAgences();
Assert.notNull(vListeAgences);
Assert.notEmpty(vListeAgences);
List<AgenceVO> vListeAgencesTrouvees = ListUtils.select(vListeAgences, new Predicate<AgenceVO>() {
public boolean evaluate(AgenceVO pAgenceVO) {
return pAgenceVO.getLibelle().startsWith("TEST_");
}
});
Assert.notNull(vListeAgencesTrouvees);
Assert.notEmpty(vListeAgencesTrouvees);
Assert.isTrue(vListeAgencesTrouvees.size() == 1);
}
}
Everything seems ok because in the log I see the following:
[TransactionalTestExecutionListener: startNewTransaction];Began transaction (1): transaction manager [org.springframework.jdbc.datasource.DataSourceTransactionManager#39d325]; rollback [true]
[DbUnitTestExecutionListener: setupOrTeardown];Executing Setup of #DatabaseTest using REFRESH on /META-INF/db-test/sampleData.xml
[AbstractTableMetaData: getDataTypeFactory];Potential problem found: The configured data type factory 'class org.dbunit.dataset.datatype.DefaultDataTypeFactory' might cause problems with the current database 'Oracle' (e.g. some datatypes may not be supported properly). In rare cases you might see this message because the list of supported database products is incomplete (list=[derby]). If so please request a java-class update via the forums.If you are using your own IDataTypeFactory extending DefaultDataTypeFactory, ensure that you override getValidDbProducts() to specify the supported database products.
[SQL: logStatement];select this_.AGC_ID as AGC1_0_0_, this_.AGC_CP as AGC2_0_0_, this_.AGC_ADR1 as AGC3_0_0_, this_.AGC_COMMUNE as AGC4_0_0_, this_.AGC_ADR2 as AGC5_0_0_, this_.AGC_LIBELLE as AGC6_0_0_, this_.AGC_MAIL as AGC7_0_0_, this_.AGC_NOM as AGC8_0_0_, this_.AGC_TEL as AGC9_0_0_ from FTN_AGENCE_AGC this_
[DbUnitTestExecutionListener: verifyExpected];Skipping #DatabaseTest expectation due to test exception class java.lang.IllegalArgumentException
[TransactionalTestExecutionListener: endTransaction];Rolled back transaction after test execution for test context [[TestContext#cdd54e testClass = AgenceDAOTest, locations = array<String>['classpath:META-INF/spring/testDataSpringContext.xml'], testInstance = com.edf.ftn.data.admin.AgenceDAOTest#16f2067, testMethod = listAgences#AgenceDAOTest, testException = java.lang.IllegalArgumentException: [Assertion failed] - this collection must not be empty: it must contain at least 1 element]]
The dbunit dataset is loaded after the transaction is created, so dataset data should be visible in select, but it is not visible. When the select is executed records in the dataset are not retrieved.
To verify if the dataset is being loaded I've tried to insert a duplicate key and an exception is launched, so I supose that de dataset is loaded correctly.
The datasource and transactionmanager configuration is:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:#${ip}:${port}:${schema}" />
<property name="username" value="${user}" />
<property name="password" value="${pass}" />
<property name="defaultAutoCommit" value="false" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
The DAO is not configured as transactional, because in the application it isn't. But I have also tried to make it transactional, and the result is the same.
I do not understand why in this line:
List<AgenceVO> vListeAgences = mAgenceDAO.getAgences();
The dataset is not visible.
Solution found
I fixed the problem by using TransactionAwareDataSourceProxy
Finally I've got the following configuration for datasource:
<bean id="dbcpDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:#${ip}:${port}:${schema}" />
<property name="username" value="${user}" />
<property name="password" value="${pass}" />
<property name="defaultAutoCommit" value="false" />
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
<constructor-arg ref="dbcpDataSource" />
</bean>
<bean id="futunoaTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
I'm getting the exception above while running a JUnit/Arquillian test in Eclipse Juno having a #Deployment method like this:
#Deployment
public static Archive<?> createDeployment() throws Exception {
File[] libs = Maven.resolver()
.loadPomFromFile("pom.xml")
.importRuntimeDependencies()
.as(File.class);
WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war")
.addClass(Permission.class)
.addClass(PermissionInterface.class)
.addClass(PermissionModel.class)
.addClass(PermissionModelInterface.class)
...
.addAsLibraries(libs)
.addAsResource(
"resources-jbossas-managed/test-persistence.xml",
"META-INF/persistence.xml")
.addAsWebResource(
EmptyAsset.INSTANCE,
ArchivePaths.create("beans.xml"));
System.out.println(war.toString(true));
return war;
}
and a persistence unit described like this:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="talmudDatabaseTest">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:/Alpha2Test</jta-data-source>
<properties>
<property name="eclipselink.target-server" value="JBoss" />
<property name="eclipselink.target-database" value="MySQL" />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.weaving" value="static" />
<property name="eclipselink.logging.level" value="FINEST" />
<property name="eclipselink.deploy-on-startup" value="True" />
<property name="eclipselink.session-event-listener" value="it.cnr.ilc.omega.model.PersistenceEventListener" />
<property name="omega.import-sql" value="false" />
<property name="omega.import-sql.postlogin-filename" value="preconstruct.sql" />
<property name="omega.import-sql.postcreate-filename" value="postconstruct.sql" />
</properties>
</persistence-unit>
</persistence>
The running JBoss 7.1.1 Final instance has been launched with this configuration (on a Macbook Pro):
-server -Xms512m -Xmx1024m -XX:MaxPermSize=512m -Djava.net.preferIPv4Stack=true -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true "-Dorg.jboss.boot.log.file=/usr/local/jboss-as-7.1.1.Final/standalone/log/boot.log" "-Dlogging.configuration=file:/usr/local/jboss-as-7.1.1.Final/standalone/configuration/logging.properties" "-Djboss.home.dir=/usr/local/jboss-as-7.1.1.Final" "-Dfile.encoding=UTF-8" "-Djboss.modules.system.pkgs=com.apple.laf,com.apple.laf.resources"
The #Test method isn't even called... the exception is thrown before it, but after the completion of the #Deployment method. Shrinkwrap creates this web archive:
test.war:
/beans.xml
/WEB-INF/
/WEB-INF/lib/
/WEB-INF/lib/atmosphere-compat-tomcat-1.1.0.beta3.jar
/WEB-INF/lib/bcprov-jdk14-1.38.jar
/WEB-INF/lib/jackson-databind-2.0.5.jar
/WEB-INF/lib/bcmail-jdk14-1.38.jar
/WEB-INF/lib/maven-aether-provider-3.0.5.jar
/WEB-INF/lib/shrinkwrap-impl-base-1.1.2.jar
/WEB-INF/lib/jcl-over-slf4j-1.6.4.jar
/WEB-INF/lib/shrinkwrap-resolver-spi-maven-2.0.0-beta-3.jar
/WEB-INF/lib/shrinkwrap-resolver-api-2.0.0-beta-3.jar
/WEB-INF/lib/maven-plugin-registry-2.0.9.jar
/WEB-INF/lib/shrinkwrap-spi-1.1.1.jar
/WEB-INF/lib/maven-model-builder-3.0.5.jar
/WEB-INF/lib/plexus-container-default-1.0-alpha-9-stable-1.jar
/WEB-INF/lib/geronimo-stax-api_1.0_spec-1.0.jar
/WEB-INF/lib/maven-plugin-api-2.0.9.jar
/WEB-INF/lib/poi-3.7.jar
/WEB-INF/lib/bcmail-jdk14-138.jar
/WEB-INF/lib/wagon-http-shared4-2.4.jar
/WEB-INF/lib/bcprov-jdk14-138.jar
/WEB-INF/lib/xmlbeans-2.3.0.jar
/WEB-INF/lib/maven-profile-2.0.9.jar
/WEB-INF/lib/poi-ooxml-schemas-3.7.jar
/WEB-INF/lib/aether-util-1.13.1.jar
/WEB-INF/lib/slf4j-log4j12-1.6.4.jar
/WEB-INF/lib/atmosphere-compat-jbossweb-1.1.0.beta3.jar
/WEB-INF/lib/jackson-core-2.0.5.jar
/WEB-INF/lib/commons-io-1.3.2.jar
/WEB-INF/lib/shrinkwrap-resolver-spi-2.0.0-beta-3.jar
/WEB-INF/lib/log4j-1.2.16.jar
/WEB-INF/lib/commons-digester-2.1.jar
/WEB-INF/lib/itext-2.1.7.js1.jar
/WEB-INF/lib/plexus-interpolation-1.14.jar
/WEB-INF/lib/classworlds-1.1-alpha-2.jar
/WEB-INF/lib/slf4j-simple-1.7.5.jar
/WEB-INF/lib/plexus-utils-2.0.6.jar
/WEB-INF/lib/annotation-detector-3.0.1.jar
/WEB-INF/lib/commons-codec-20041127.091804.jar
/WEB-INF/lib/atmosphere-compat-tomcat7-1.1.0.beta3.jar
/WEB-INF/lib/commons-collections-2.1.jar
/WEB-INF/lib/el-api-2.2.jar
/WEB-INF/lib/jdtcore-3.1.0.jar
/WEB-INF/lib/primefaces-3.5.jar
/WEB-INF/lib/commonj.sdo-2.1.1.v201112051852.jar
/WEB-INF/lib/shrinkwrap-resolver-impl-maven-2.0.0-beta-3.jar
/WEB-INF/lib/eclipselink-staticweave-maven-plugin-1.0.4.jar
/WEB-INF/lib/aether-spi-1.13.1.jar
/WEB-INF/lib/aether-impl-1.13.1.jar
/WEB-INF/lib/stax-api-1.0.1.jar
/WEB-INF/lib/jcommon-1.0.15.jar
/WEB-INF/lib/commons-logging-1.1.1.jar
/WEB-INF/lib/wagon-provider-api-2.4.jar
/WEB-INF/lib/xml-apis-1.4.01.jar
/WEB-INF/lib/plexus-compiler-javac-2.1.jar
/WEB-INF/lib/shrinkwrap-api-1.1.1.jar
/WEB-INF/lib/shrinkwrap-resolver-api-maven-2.0.0-beta-3.jar
/WEB-INF/lib/jsoup-1.6.3.jar
/WEB-INF/lib/plexus-component-api-1.0-alpha-33.jar
/WEB-INF/lib/maven-project-2.0.9.jar
/WEB-INF/lib/shrinkwrap-resolver-impl-maven-archive-2.0.0-beta-3.jar
/WEB-INF/lib/httpcore-4.2.3.jar
/WEB-INF/lib/maven-settings-builder-3.0.5.jar
/WEB-INF/lib/shrinkwrap-resolver-api-maven-archive-2.0.0-beta-3.jar
/WEB-INF/lib/maven-artifact-2.0.9.jar
/WEB-INF/lib/poi-ooxml-3.7.jar
/WEB-INF/lib/wagon-http-lightweight-2.4.jar
/WEB-INF/lib/dom4j-1.6.1.jar
/WEB-INF/lib/jena-core-2.10.0.jar
/WEB-INF/lib/slf4j-api-1.6.4.jar
/WEB-INF/lib/eclipselink-2.4.0.jar
/WEB-INF/lib/aether-connector-wagon-1.13.1.jar
/WEB-INF/lib/xercesImpl-2.10.0.jar
/WEB-INF/lib/castor-1.2.jar
/WEB-INF/lib/jfreechart-1.0.12.jar
/WEB-INF/lib/maven-repository-metadata-3.0.5.jar
/WEB-INF/lib/bctsp-jdk14-1.38.jar
/WEB-INF/lib/jasperreports-fonts-4.0.0.jar
/WEB-INF/lib/shrinkwrap-resolver-spi-maven-archive-2.0.0-beta-3.jar
/WEB-INF/lib/jena-tdb-0.10.0.jar
/WEB-INF/lib/commons-lang3-3.0.1.jar
/WEB-INF/lib/maven-artifact-manager-2.0.9.jar
/WEB-INF/lib/plexus-classworlds-2.4.jar
/WEB-INF/lib/maven-settings-3.0.5.jar
/WEB-INF/lib/commons-beanutils-1.8.0.jar
/WEB-INF/lib/jena-arq-2.10.0.jar
/WEB-INF/lib/httpclient-4.2.3.jar
/WEB-INF/lib/javax.persistence-2.0.4.v201112161009.jar
/WEB-INF/lib/aether-api-1.13.1.jar
/WEB-INF/lib/maven-model-3.0.5.jar
/WEB-INF/lib/atmosphere-runtime-1.1.0.beta3.jar
/WEB-INF/lib/plexus-compiler-api-2.1.jar
/WEB-INF/lib/jena-iri-0.9.5.jar
/WEB-INF/lib/jackson-annotations-2.0.5.jar
/WEB-INF/lib/jasperreports-5.0.0.jar
/WEB-INF/lib/wagon-file-2.4.jar
/WEB-INF/classes/
/WEB-INF/classes/META-INF/
/WEB-INF/classes/META-INF/persistence.xml
/WEB-INF/classes/it/
/WEB-INF/classes/it/cnr/
/WEB-INF/classes/it/cnr/ilc/
/WEB-INF/classes/it/cnr/ilc/omega/
/WEB-INF/classes/it/cnr/ilc/omega/resources/
/WEB-INF/classes/it/cnr/ilc/omega/resources/model/
/WEB-INF/classes/it/cnr/ilc/omega/resources/model/SourceInterface.class
/WEB-INF/classes/it/cnr/ilc/omega/resources/model/Source.class
/WEB-INF/classes/it/cnr/ilc/omega/resources/model/AttachmentInterface.class
/WEB-INF/classes/it/cnr/ilc/omega/resources/model/ResourceType.class
/WEB-INF/classes/it/cnr/ilc/omega/resources/model/ResourceInterface.class
/WEB-INF/classes/it/cnr/ilc/omega/resources/model/Resource.class
/WEB-INF/classes/it/cnr/ilc/omega/resources/model/Attachment.class
/WEB-INF/classes/it/cnr/ilc/omega/resources/model/ResourceTypeInterface.class
/WEB-INF/classes/it/cnr/ilc/omega/access/
/WEB-INF/classes/it/cnr/ilc/omega/access/LoginViewController.class
/WEB-INF/classes/it/cnr/ilc/omega/access/LoginViewControllerInterface.class
/WEB-INF/classes/it/cnr/ilc/omega/access/model/
/WEB-INF/classes/it/cnr/ilc/omega/access/model/Task.class
/WEB-INF/classes/it/cnr/ilc/omega/access/model/Role.class
/WEB-INF/classes/it/cnr/ilc/omega/access/model/Credentials.class
/WEB-INF/classes/it/cnr/ilc/omega/access/model/PermissionModel.class
/WEB-INF/classes/it/cnr/ilc/omega/access/model/TaskInterface.class
/WEB-INF/classes/it/cnr/ilc/omega/access/model/UserInterface.class
/WEB-INF/classes/it/cnr/ilc/omega/access/model/UserModelInterface.class
/WEB-INF/classes/it/cnr/ilc/omega/access/model/TaskModelInterface.class
/WEB-INF/classes/it/cnr/ilc/omega/access/model/PermissionInterface.class
/WEB-INF/classes/it/cnr/ilc/omega/access/model/PermissionModelInterface.class
/WEB-INF/classes/it/cnr/ilc/omega/access/model/User.class
/WEB-INF/classes/it/cnr/ilc/omega/access/model/LogoutEvent.class
/WEB-INF/classes/it/cnr/ilc/omega/access/model/TaskModel.class
/WEB-INF/classes/it/cnr/ilc/omega/access/model/Permission.class
/WEB-INF/classes/it/cnr/ilc/omega/access/model/UserModel.class
/WEB-INF/classes/it/cnr/ilc/omega/model/
/WEB-INF/classes/it/cnr/ilc/omega/model/AbstractEntityModel.class
/WEB-INF/classes/it/cnr/ilc/omega/model/AbstractEntityInterface.class
/WEB-INF/classes/it/cnr/ilc/omega/model/EntityDeleteEvent.class
/WEB-INF/classes/it/cnr/ilc/omega/model/EntityCreateEvent.class
/WEB-INF/classes/it/cnr/ilc/omega/model/EntityUpdateEvent.class
/WEB-INF/classes/it/cnr/ilc/omega/model/AbstractEntityModelInterface.class
/WEB-INF/classes/it/cnr/ilc/omega/model/AbstractEntity$Status.class
/WEB-INF/classes/it/cnr/ilc/omega/model/PersistenceEventListener.class
/WEB-INF/classes/it/cnr/ilc/omega/model/AbstractEntity.class
/WEB-INF/classes/it/cnr/ilc/omega/BaseController.class
/WEB-INF/classes/it/cnr/ilc/omega/Resources.class
/WEB-INF/classes/it/cnr/ilc/omega/reference/
/WEB-INF/classes/it/cnr/ilc/omega/reference/model/
/WEB-INF/classes/it/cnr/ilc/omega/reference/model/Reference.class
/WEB-INF/classes/it/cnr/ilc/omega/reference/model/ReferenceInterface.class
After that, Arquillian adds the archive on the active instance of JBoss, but the deployment can't terminate its operations. I've also managed to raise the memory for the JVM, but it doesn't seem to work. If I remove the libs form the archive, the #Test method is passed correctly, but the Session bean i'd like to inject:
#Inject
LoginViewController loginViewController;
isn't resolved like it should.
Can anyone help to find why the exception occurs? Thanks in advance... any help is appreciated!
.addAsWebResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
should be
.addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
HINT : My hosting tomcat system provides only 20 db connections
My working project in localhsot
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
p:username="${jdbc.username}" p:password="${jdbc.password}" />
This worked good in localhost, but in production it run for a while and Exception : "user has allready max no of connection".
After many google
I used c3p0
<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}"/>
</bean>
This worked in localhost, but same problem in production server
Hint: I think some config in c3p0 can solve this. Please help me with you suggestion (My hosting provides only 20 connections)
Also i tried tomcat
<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSourceFactory">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="maxActive" value="20"/>
</bean>
The above tomcat code is wrong and will not work - because wrong property (I know that). How to set this for my production use(only 20 connections)
If you know how to use tomcat pool please help us.
I also used bonecp
<bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close" >
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="idleConnectionTestPeriod" value="60"/>
<property name="idleMaxAge" value="240"/>
<property name="maxConnectionsPerPartition" value="10"/>
<property name="minConnectionsPerPartition" value="5"/>
<property name="partitionCount" value="1"/>
<property name="acquireIncrement" value="5"/>
<property name="statementsCacheSize" value="1000"/>
<property name="releaseHelperThreads" value="3"/>
</bean>
This worked in localhost but same problem in production "user has to many connections".
I also tried apache-dbcp
As per tomcat 7 documentation - dbcp is no longer and tomcat will be bundled with pool. Even though i used dbcp and i cannot run my program. (I added only one jar and error was some class not found during project run)
As per my own idea :
I think above mentioned settings will be problem. Please help me with your suggestions. I'm not using hibernate up to now because of heavy weight. If hibernate can solve this problem please let us know.
EDITED
Currently I'm using this code. Is this code correct to my use(20 connection)
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"
p:driverClass="${jdbc.driverClassName}" p:jdbcUrl="${jdbc.url}"
p:user="${jdbc.username}" p:password="${jdbc.password}"
p:acquireIncrement="1"
p:checkoutTimeout="1"
p:idleConnectionTestPeriod="5"
p:maxIdleTime="5"
p:maxIdleTimeExcessConnections="1"
p:maxPoolSize="20" p:maxStatements="0" p:maxStatementsPerConnection="0"
p:minPoolSize="1"
p:numHelperThreads="100"
p:overrideDefaultUser="${jdbc.username}" p:overrideDefaultPassword="${jdbc.password}"
p:propertyCycle="3"
p:testConnectionOnCheckin="true"
p:unreturnedConnectionTimeout="5" />
DAO code :
#Repository
public class TutorialsDAOImpl implements TutorialsDAO {
//---
private JdbcTemplate jdbcTemplate;
private DataSource dataSource;
#Autowired
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
//---
#Override
public List<TutorialsCategory_vo> getTutorialsCategory() {
sql = "SELECT * FROM `tutorials_category` ORDER BY `slug` ASC;";
List<TutorialsCategory_vo> vo = null;
try {
vo = this.jdbcTemplate.query(sql, new Object[]{}, tutorialsCategory_mapper);
} catch (Exception e) {
log.log(Level.SEVERE, null, e);
}
return vo;
}
These are the codes i'm using. If there is any error/corrections pls correct me.
Edited (for Arun P Johny 's question)
My current project url.
I updated my current code above.
This is my final c3p0 settings:
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"
p:driverClass="${jdbc.driverClassName}" p:jdbcUrl="${jdbc.url}"
p:user="${jdbc.username}" p:password="${jdbc.password}"
p:acquireIncrement="1"
p:checkoutTimeout="3000"
p:idleConnectionTestPeriod="5"
p:maxIdleTime="3"
p:maxIdleTimeExcessConnections="1"
p:maxPoolSize="20" p:maxStatements="20000" p:maxStatementsPerConnection="1000"
p:minPoolSize="1"
p:numHelperThreads="1000"
p:overrideDefaultUser="${jdbc.username}" p:overrideDefaultPassword="${jdbc.password}"
p:propertyCycle="3"
p:statementCacheNumDeferredCloseThreads="1"
p:testConnectionOnCheckin="true"
p:unreturnedConnectionTimeout="7" />
This works fine, but taking more time(1 or 2 secounds - not more than 3 secounds).
I also checked this code by shutting down mysql. My program waited up to, i start mysql. This is good. This code waits for all db connections to complete and out put correctly.
Can we make this settings even faster? Hint: my server provides only 20 connections.
If you provide a correct answer i'll make it as right answer, after checking.