i have really strange problem. My Spring web-application seems to have a memory-leak.
i'm using Spring 3.2
my Tomcat config:
JAVA_OPTS="-Dfile.encoding=UTF-8 -server -Xms512m -Xmx1024m
-XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=128m
-XX:MaxPermSize=256m -XX:+DisableExplicitGC -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/dumps"
my dataSource declaration:
<!-- declare transactionManager -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<beans:bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<beans:property name="dataSource" ref="dataSource"></beans:property>
</beans:bean>
<beans:bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
<beans:property name="url" value="jdbc:mysql://localhost/test" />
<beans:property name="username" value="User" />
<beans:property name="password" value="password" />
<beans:property name="initialSize" value="5" />
<beans:property name="maxActive" value="55" />
<beans:property name="maxIdle" value="20" />
<beans:property name="minIdle" value="10" />
<beans:property name="maxWait" value="10000" />
<beans:property name="minEvictableIdleTimeMillis" value="55000" />
<beans:property name="timeBetweenEvictionRunsMillis" value="34000" />
<beans:property name="validationQuery" value="SELECT 1" />
<beans:property name="testOnBorrow" value="true" />
<beans:property name="removeAbandoned" value="true"/>
<beans:property name="removeAbandonedTimeout" value="60"/>
<beans:property name="logAbandoned" value="true"/>
</beans:bean>
<beans:bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<beans:property name="dataSource" ref="dataSource"></beans:property>
</beans:bean>
i'm injecting the jdbcTemplate into dao. I'm using Transaction-Annotations as well.
this is what i got from Memory Analizer (MAT):
The class "com.mysql.jdbc.NonRegisteringDriver", loaded by "org.apache.catalina.loader.StandardClassLoader # 0x515c1390", occupies 758.845.296 (72,57%) bytes. The memory is accumulated in one instance of "java.util.concurrent.ConcurrentHashMap$Segment[]" loaded by "system class loader".
in the detail-view i saw this:
com.mysql.jdbc.NonRegisteringDriver$ConnectionPhantomReference
First 10 of 14.360 objects. Number of Objects: 14.360. Used Heap Size: 459.520. Retained Heap Size: 732.819.568
i found this: bug report, but i'm using 5.1.29, so i think i shouldn't have this problem. But maybe the problem is somewhere in apache dbcp. Can someone help me? Is my configuration ok? Is there a problem in JDBCTemplate + TransactionManager?
here is 1 of my services. I use Transactions in the services, is it ok?
#Service
public class ModerationServiceImpl implements ModerationService {
#Autowired
private EventService eventService;
#Autowired
private ContentManagementService cmService;
#Autowired
private IconDao iconDao;
#Transactional(rollbackFor = Exception.class)
#Override
public void activateUserIcon(long userIconId, long userId, String comment)
throws IconNotFoundException, NoPermissionException, IOException,
IconNotAssignedToUserException, WrongIconStateException {
if(!iconDao.isAssignedToUser(userIconId))
throw new IconNotAssignedToUserException("icon: " + userIconId + " is not assigned to a user and can't be activated!");
cmService.activateUserIcon(userIconId);
eventService.writeUserIconEvent(userIconId, userId, new Date().getTime(), Enum_ServerEvent.verified, Enum_UserIconState.approved, comment);
}
and here is 1 of my DAO's:
#Repository
public class IconDaoImpl extends DB_Contract implements IconDao{
#Autowired
private JdbcTemplate jdbcTemplate;
#Override
public IconData getUserIconById(long iconId) throws IconNotFoundException {
String sql = SELECT + UserIcon.CN_ServerID + NEXT +
UserIcon.CN_State + NEXT +
UserIcon.CN_Ref +
FROM + UserIcon.TABLE_NAME + WHERE + UserIcon.CN_ServerID + " = ?";
try{
return jdbcTemplate.queryForObject(sql, new UserIconRowMapper(), iconId);
}catch (EmptyResultDataAccessException e){
throw new IconNotFoundException("couldn't find icon for id: " + iconId);
}
}
Related
How can i handle exceptions from Spring context .
Consider the context
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
<property name="URL" value="jdbc:oracle:thin:#localhost:1521/xe" />
<property name="user" value="abc" />
<property name="password" value="abc" />
</bean>
<bean id="abc" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" >
<property name="dataSource" ref="dataSource" />
<property name="persistenceUnitName" value="default" />
<property name="persistenceXmlLocation" value="classpath*:META-INF/abc-persistence.xml" />
</bean>
And am loading context in main method
public static void main(String[] args) {
ApplicationContext applicationContext = null;
try {
applicationContext = new ClassPathXmlApplicationContext("/META-INF/spring/test.xml");
} catch (Exception e) {
System.out.println("Exception caugtht " + e);
}
}
Lets say database is down .now when i load context exceptions are not caught in catch block. Is there any way to handle this ?
I am trying to add multiple records into an Oracle 12c database using a simple spring jdbcTemplate call to batchUpdate() method. The code that makes the batchUpdate() call is in my DAO class. However the code that calls the service method is multi-threaded.
This is what my DAO class looks like (there are more like this):
public void batchInsertSessionSignature(final List<SessionSignature> sessionSignatures, DataSource dataSource) {
Assert.notNull(sessionSignatures, "Checking to see if the SessionSignature objects passed in are null");
if (dataSource != null) {
jdbcTemplate.setDataSource(dataSource);
}
if (!sessionSignatures.isEmpty()) {
log.debug("Inserting batch entries into lev_session_signature_temp of size: " + sessionSignatures.size());
int[] res = jdbcTemplate.batchUpdate(insertSessionSig, new BatchPreparedStatementSetter() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
#Override
public void setValues(PreparedStatement pstmt, int i) throws SQLException {
SessionSignature ss = sessionSignatures.get(i);
String created_date = sdf.format(ss.getCreated_date());
pstmt.setLong(1, ss.getId());
pstmt.setString(2, ss.getHost());
pstmt.setString(3, ss.getSession_id());
pstmt.setString(4, ss.getIp_address());
pstmt.setString(5, ss.getAccountName());
try {
pstmt.setInt(6, sysInfoBean.getSysinfoID(ss.getSysinfo()));
pstmt.setDate(7, new Date(sdf.parse(created_date).getTime()));
} catch (ParseException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
pstmt.setString(8, ss.getCountry());
pstmt.setInt(9, ss.getAccountID());
pstmt.setString(10, ss.getBusinessUnit());
}
#Override
public int getBatchSize() {
return sessionSignatures.size();
}
});
log.debug(res.length + " entries inserted into lev_session_signature_temp");
}
}
This is the service layer method that makes the call to the DAO classes (the method is thread safe)
#Transactional(propagation= Propagation.REQUIRES_NEW, rollbackFor=Exception.class)
public synchronized void writeTargetDaoEntries(TargetDao targetDao, DataSource dataSource, ArrayList<SessionSignature> tgtSessionSignatures,
ArrayList<Session> tgtSession, ArrayList<SearchGroup> tgtSearchGroup, ArrayList<Search> tgtSearches,
ArrayList<LuceneEvent> tgtEvents, ArrayList<EventAnalysisDaoUtil> eventAnalysisList) throws Exception {
targetDao.batchInsertSessionSignatures(tgtSessionSignatures, dataSource);
targetDao.batchInsertUserSessions(tgtSession, dataSource);
targetDao.batchInsertSearchGroups(tgtSearchGroup, dataSource);
targetDao.batchInsertSearches(tgtSearches, dataSource);
targetDao.batchInsertEvents(tgtEvents, dataSource);
targetDao.batchInsertEventAnalysis(eventAnalysisList, dataSource);
}
My spring configuration looks like this
<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:annotation-config/>
<context:property-placeholder location="app.properties"/>
<bean id="dataSourceQa" class="oracle.ucp.jdbc.PoolDataSourceFactory"
factory-method="getPoolDataSource" lazy-init="true">
<property name="connectionFactoryClassName"
value="oracle.jdbc.pool.OracleDataSource" />
<property name="user" value="${qaTargetId}" />
<property name="password" value="${qaTargetPswd}" />
<property name="URL" value="${qaTargetURL}" />
<property name="minPoolSize" value="2" />
<property name="maxPoolSize" value="10" />
</bean>
<bean id="dataSourceProd" class="oracle.ucp.jdbc.PoolDataSourceFactory"
factory-method="getPoolDataSource" lazy-init="true">
<property name="connectionFactoryClassName"
value="oracle.jdbc.pool.OracleDataSource" />
<property name="user" value="${prodSourceId}" />
<property name="password" value="${prodSourcePswd}" />
<property name="URL" value="${prodSourceURL}" />
<property name="minPoolSize" value="2" />
<property name="maxPoolSize" value="10" />
</bean>
<!-- JDBC Template Configuration -->
<bean id = "jdbcTemplate" class = "org.springframework.jdbc.core.JdbcTemplate">
<property name = "dataSource" ref = "dataSourceQa"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSourceQa" />
</bean>
<bean id="taskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="5" />
<property name="maxPoolSize" value="10" />
<property name="WaitForTasksToCompleteOnShutdown" value="true" />
</bean>
<!-- DAO Bean Configuration -->
<bean id = "eventDaoBean" class = "com.uptodate.lucene.tool.analysis.transfer.oracleDao.EventDao" />
<bean id = "searchDaoBean" class = "com.uptodate.lucene.tool.analysis.transfer.oracleDao.SearchDao" />
<bean id = "searchGroupDaoBean" class = "com.uptodate.lucene.tool.analysis.transfer.oracleDao.SearchGroupDao" />
<bean id = "userSessionDaoBean" class = "com.uptodate.lucene.tool.analysis.transfer.oracleDao.UserSessionDao" />
<bean id = "sessionSignatureDaoBean" class = "com.uptodate.lucene.tool.analysis.transfer.oracleDao.SessionSignatureDao" />
<bean id = "eventAnalysisDaoBean" class = "com.uptodate.lucene.tool.analysis.transfer.oracleDao.EventAnalysisDao" />
<bean id = "dailySummaryDaoBean" class = "com.uptodate.lucene.tool.analysis.transfer.oracleDao.DailySummaryDao" />
<bean id = "keyGeneratorBean" class = "com.uptodate.lucene.tool.analysis.transfer.oracleDao.KeyGenerator" />
<bean id = "machineLearningDaoBean" class = "com.uptodate.lucene.tool.analysis.transfer.oracleDao.MachineLearningDao" />
<bean id = "sourceDaoBean" abstract = "true" class = "com.uptodate.lucene.tool.analysis.transfer.oracleDao.SourceDao" />
<bean id = "desktopSourceDaoBean" class = "com.uptodate.lucene.tool.analysis.transfer.oracleDao.DesktopSourceDao" />
<bean id = "mobileSourceDaoBean" class = "com.uptodate.lucene.tool.analysis.transfer.oracleDao.MobileSourceDao" />
<bean id = "webSourceDaoBean" class = "com.uptodate.lucene.tool.analysis.transfer.oracleDao.WebSourceDao" />
<bean id = "tempTableDaoBean" class = "com.uptodate.lucene.tool.analysis.transfer.oracleDao.TempTableDao" />
<bean id = "targetDaoBean" class = "com.uptodate.lucene.tool.analysis.transfer.oracleDao.TargetDao">
<constructor-arg ref = "eventDaoBean" />
<constructor-arg ref = "searchDaoBean" />
<constructor-arg ref = "searchGroupDaoBean" />
<constructor-arg ref = "userSessionDaoBean" />
<constructor-arg ref = "sessionSignatureDaoBean" />
<constructor-arg ref = "eventAnalysisDaoBean" />
</bean>
<!-- Parser Bean Configuration -->
<bean id = "userSessionParserBean" class = "com.uptodate.lucene.tool.analysis.transfer.parser.UserSessionParser" scope = "prototype" />
<bean id = "searchParserBean" class = "com.uptodate.lucene.tool.analysis.transfer.parser.SearchParser" scope = "prototype" />
<bean id = "searchGroupParserBean" class = "com.uptodate.lucene.tool.analysis.transfer.parser.SearchGroupParser" scope = "prototype" />
<bean id = "eventParserBean" abstract = "true" class = "com.uptodate.lucene.tool.analysis.transfer.parser.EventParser" scope = "prototype" />
<bean id = "mobileEventParserBean" class = "com.uptodate.lucene.tool.analysis.transfer.parser.MobileEventParser" scope = "prototype" />
<bean id = "webEventParserBean" class = "com.uptodate.lucene.tool.analysis.transfer.parser.WebEventParser" scope = "prototype" />
<bean id = "logParserBean" class = "com.uptodate.lucene.tool.analysis.transfer.LogParser" scope = "prototype">
<constructor-arg ref = "keyGeneratorBean" />
<constructor-arg ref = "searchParserBean" />
<constructor-arg ref = "searchGroupParserBean" />
<constructor-arg ref = "userSessionParserBean" />
</bean>
<!-- Transfer Bean Configuration -->
<bean id = "dailySummaryGeneratorBean" class = "com.uptodate.lucene.tool.analysis.transfer.DailySummaryGenerator" />
<!-- Util Bean Configuration -->
<bean id = "sysInfoBean" class = "com.uptodate.lucene.tool.analysis.vo.SysInfo">
<property name = "dataSource" ref = "dataSourceProd" />
</bean>
I have tried adding support for transactions hoping that would help make sure the entries are committed to the database but that did not help. I can see in the code that all entries sent to the database were written to it but when I check the number of records in the database the same number is not reflected. I'm not sure if this is because of the multithreaded nature of the code that a batch of entires is overwritten somehow? Using 1 thread seems to work fine making me believe its a multithreading issue but I'm not sure where the problem is. Any help on this issue is appreciated.
I have two transaction managers defined in my context file as follows
<tx:annotation-driven transaction-manager="firstTransactionManager" />
<bean id="secondDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="---" />
<property name="url" value="datasource1" />
<property name="username" value="----" />
<property name="password" value="----" />
</bean>
<bean id="firstTransactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="firstDataSource" />
<qualifier value="firstTxManager"/>
</bean>
<bean id="secondTransactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="secondDataSource" />
<qualifier value="secondTxManager"/>
</bean>
<bean id="firstDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="---" />
<property name="url" value="datasource2" />
<property name="username" value="---" />
<property name="password" value="---" />
</bean>
And I my class definitions are as follows
#Transactional("firstTransactionManager")
public class JdbcMain {
#Autowired
private static DataSource dataSource;
public DataSource getDataSource() {
return dataSource;
}
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
public static void main(String args[]){
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
TransactionExample example = (TransactionExample) ctx.getBean("transExample");
example.create();
}
}
And my example class is as follows:
#Transactional("secondTransactionManager")
public void create(DataSource dataSource2) {
try {
this.jdbcTemplate = new JdbcTemplate(dataSource2);
String sql = "insert into testtable values (?,?)";
getJdbcTemplate().update(sql,1,"1244343");
String marksSql="insert into testtable values (?,?)";
int i=2/0; //added to depict roll back behaviour of the transaction when exception occurs
getJdbcTemplate().update(marksSql,2,"sujay");
System.out.println("transaction committed");
} catch (RuntimeException e) {
throw e;
}
}
But the second transaction manager doesn't seem to work and the transaction is not rolled back (The first insert is executed). Can you provide me an idea.
I am looking for a guidance/solution with Spring batch integration. I have a directory to which external application will send xml files. My application should read the file content and move the file to another directory.
The application should be able to process the files in parallel.
Thanks in advance.
You can use Spring Integration ftp / sftp combined with Spring Batch:
1.Spring Integration Ftp Configuration :
<bean id="ftpClientFactory"
class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
<property name="host" value="${host.name}" />
<property name="port" value="${host.port}" />
<property name="username" value="${host.username}" />
<property name="password" value="${host.password}" />
<property name="bufferSize" value="100000"/>
</bean>
<int:channel id="ftpChannel" />
<int-ftp:outbound-channel-adapter id="ftpOutbound"
channel="ftpChannel" remote-directory="/yourremotedirectory/" session-factory="ftpClientFactory" use-temporary-file-name="false" />
2.Create your reader and autowire a service to provide your items if needed :
#Scope("step")
public class MajorItemReader implements InitializingBean{
private List<YourItem> yourItems= null;
#Autowired
private MyService provider;
public YourItem read() {
if ((yourItems!= null) && (yourItems.size() != 0)) {
return yourItems.remove(0);
}
return null;
}
//Reading Items from Service
private void reloadItems() {
this.yourItems= new ArrayList<YourItem>();
// use the service to provide your Items
if (yourItems.isEmpty()) {
yourItems= null;
}
}
public MyService getProvider() {
return provider;
}
public void setProvider(MyService provider) {
this.provider = provider;
}
#Override
public void afterPropertiesSet() throws Exception {
reloadItems();
}
}
3. Create Your Own Item Processor
public class MyProcessor implements
ItemProcessor<YourItem, YourItem> {
#Override
public YourItem process(YourItem arg0) throws Exception {
// Apply any logic to your Item before transferring it to the writer
return arg0;
}
}
4. Create Your Own Writer :
public class MyWriter{
#Autowired
#Qualifier("ftpChannel")
private MessageChannel messageChannel;
public void write(YourItem pack) throws IOException {
//create your file and from your Item
File file = new File("the_created_file");
// Sending the file via Spring Integration Ftp Channel
Message<File> message = MessageBuilder.withPayload(file).build();
messageChannel.send(message);
}
5.Batch Configuration :
<bean id="dataSourcee"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="" />
<property name="url" value="" />
<property name="username" value="" />
<property name="password" value="" />
</bean>
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
<property name="dataSource" ref="dataSourcee" />
<property name="transactionManager" ref="transactionManagerrr" />
<property name="databaseType" value="" />
</bean>
<bean id="transactionManagerrr"
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
6.Another ApplicationContext file to Configure Your Job :
<context:annotation-config />
<bean id="provider" class="mypackage.MyService" />
<context:component-scan base-package="mypackage" />
<bean id="myReader" class="mypackage.MyReader"
<property name="provider" ref="provider" />
</bean>
<bean id="myWriter" class="mypackage.MyWriter" />
<bean id="myProcessor" class="mypackage.MyProcessor" />
<bean id="mReader"
class="org.springframework.batch.item.adapter.ItemReaderAdapter">
<property name="targetObject" ref="myReader" />
<property name="targetMethod" value="read" />
</bean>
<bean id="mProcessor"
class="org.springframework.batch.item.adapter.ItemProcessorAdapter">
<property name="targetObject" ref="myProcessor" />
<property name="targetMethod" value="process" />
</bean>
<bean id="mWriter"
class="org.springframework.batch.item.adapter.ItemWriterAdapter">
<property name="targetObject" ref="myWriter" />
<property name="targetMethod" value="write" />
</bean>
<batch:job id="myJob">
<batch:step id="step01">
<batch:tasklet>
<batch:chunk reader="mReader" writer="mWriter"
processor="mProcessor" commit-interval="1">
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="myRunScheduler" class="mypackage.MyJobLauncher" />
<task:scheduled-tasks>
<task:scheduled ref="myJobLauncher" method="run"
cron="0 0/5 * * * ?" />
<!-- this will maker the job runs every 5 minutes -->
</task:scheduled-tasks>
7.Finally Configure A launcher to launch your job :
public class MyJobLauncher {
#Autowired
private JobLauncher jobLauncher;
#Autowired
#Qualifier("myJob")
private Job job;
public void run() {
try {
String dateParam = new Date().toString();
JobParameters param = new JobParametersBuilder().addString("date",
dateParam).toJobParameters();
JobExecution execution = jobLauncher.run(job, param);
execution.stop();
} catch (Exception e) {
e.printStackTrace();
}
}
I'm new in spring, I have 3 projects in my eclipse. One JPA.jar, client.jar and a Web.war.
I am going to deploy these on Tomcat 6 so all the dependencies are mainly on the Web.war.
My problem is that I can persist data in the oracle data base but I cannot get(select) the data from the Query object in the DAO :(.
here is my servlet-context
</beans:bean>
<!-- Oracle Driver -->
<beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<beans:property name="url" value="jdbc:oracle:thin:#//sapodev.sapo.co.za:1523/P3P"/>
<beans:property name="username" value="pensions"/>
<beans:property name="password" value="pensions"/>
</beans:bean>
<!-- JPA EntityManagerFactory -->
<beans:bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<beans:property name="persistenceUnitName" value="frameworkPU"/>
<beans:property name="dataSource" ref="dataSource"/>
<beans:property name="jpaVendorAdapter">
<beans:bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<beans:property name="showSql" value="true"/>
<!-- <property name="generateDdl" value="false"/> -->
<beans:property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect"/>
</beans:bean>
</beans:property>
</beans:bean>
<beans:bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<beans:property name="entityManagerFactory" ref="entityManagerFactory" />
<beans:property name="dataSource" ref="dataSource"/>
</beans:bean>
<beans:bean id="persistenceAnnotation" class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<beans:bean id="contactService" class="za.co.sapo.service.ContactServiceImpl"/>
<context:component-scan base-package="za.co.sapo.controller" />
<context:annotation-config />
<context:component-scan base-package="za.co.sapo.dao"/>
</beans:beans>
Here is the DAO class
public List<DevUserTab> findUsers() {
List<DevUserTab> list = null;
log.info("DD");
try{
TypedQuery<DevUserTab> query = this.entityManagerFactory.createNamedQuery("SELECT d from DevUserTab d", DevUserTab.class);
list= query.getResultList();
} catch(Exception e){
log.info(" EE");
e.printStackTrace();
}
return list;
}
Here is the service class
#Autowired
public ContactDAO contactDAO;
public List findUsers() {
// TODO Auto-generated method stub
ContactDAO contact = new ContactDAO();
List users = contact.findUsers();
return users;
}
My controller
#RequestMapping(value = "/table")
public ModelAndView getContacts(Locale locale, Model model) {
logger.info("Getting the Contacts for us "+ locale.toString());
ModelAndView mv = new ModelAndView("/table");
try{
List<Contact> objects = ServiceLayerContext.getContext().findContacts();
mv.addObject("objects", objects );
} catch(Exception e){
e.printStackTrace();
}
return mv;
}
The createNamedQuery expects you to be referencing a query you configured in your persistence.xml
When specifying the JPQL directly as you are doing, you need to use the createQuery method instead.