Total members 11890 |It is currently Thu Apr 18, 2024 4:40 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Following code use EJB QL to select a group a topics by list of dates .

Using the entity manager
Code:
List<Topic> results = entitymanager.createQuery(  
    
"select t from Topic t where t.creationDate in (:datesList)")  
    
.setParameter("datesList", datesList)  
    
.getResultList(); 


You can put this query in orm.xml as named query :

Code:

<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="1.0"
    xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd">

    <named-query name="getTopicsFromList">
        <query>select t from Topic t where t.creationDate in (:datesList)</query>
    </named-query>
</entity-mappings>



In this case you will need to call entitymanager create name query function :

Code:
 
public List
<Topic> getTopicsFromDates(List<Date> dateList) {
    List<Topic> topicList = null; 
    javax
.persistence.Query query;
    try {
      query = entitymanager.createNamedQuery("getTopicsFromList"); 
      query
.setParameter("datesList", dateList)  ;
      topicList  = query.getResultList();
 
            
} catch (Exception exception) {
           
exception.printStackTrace();
             }
        return topicList ;
}
 




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : EJB-QL IN where query
 update query example     -  
 using parameter with name query     -  
 Run query and search from ASP     -  
 more than one parameter with name query     -  
 SQL AND OR in WHERE query Commands     -  
 select query example in php     -  
 SQL LIKE query Command     -  
 query about execution     -  
 insert query example     -  
 Query about jsp and printer     -  



Topic Tags

Java JPA
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com