Order By issue Kundera 2.9

54 views
Skip to first unread message

Alaa Abu Zaghleh

unread,
May 5, 2014, 7:28:36 PM5/5/14
to kundera...@googlegroups.com
Hi,
I am using Kundera for mapping my cassandra database to model classes I have the following table definition

CREATE TABLE users_activities(
    user_id UUID ,
    id UUID ,
    created_date BIGINT ,
    activity_type TEXT ,
    media_id UUID,
    comment_id UUID ,
    target_users LIST<UUID> ,
    PRIMARY KEY (user_id, created_date, id)    
)WITH CLUSTERING ORDER BY (created_date DESC, id DESC) ;
CREATE INDEX users_activity_activity_type_idx on users_activities(activity_type) ;
CREATE INDEX users_activities_media_id_idx on users_activities(media_id) ; 

this is my model

@Embeddable
public class UserActivityKey {
   
    @Column(name="user_id")
    private UUID userId ;
    @Column(name="created_date")
    private Long createdDate ;
    @Column(name="id")
    private UUID id ;
   
    public UUID getUserId() {
        return userId;
    }
    public void setUserId(UUID userId) {
        this.userId = userId;
    }
    public Long getCreatedDate() {
        return createdDate;
    }
    public void setCreatedDate(Long createdDate) {
        this.createdDate = createdDate;
    }
    public UUID getId() {
        return id;
    }
    public void setId(UUID id) {
        this.id = id;
    }
}



@Entity
@Table(name = "users_activities", schema = "auditionspace@auditionspace_pu")
@XmlRootElement(name = "userActivities")
public class UserActivity {
    @EmbeddedId
    private UserActivityKey key ;
    @Column(name= "activity_type")
    private String activityType ;
    @Column(name="media_id")
    private UUID mediaId ;
    @Column(name="comment_id")
    private UUID commentId ;
    @Column(name="target_users")
    private List<UUID> targetUsers ;
   
    public UserActivityKey getKey() {
        return key;
    }
    public void setKey(UserActivityKey key) {
        this.key = key;
    }
    public String getActivityType() {
        return activityType;
    }
    public void setActivityType(String activityType) {
        this.activityType = activityType;
    }
    public UUID getMediaId() {
        return mediaId;
    }
    public void setMediaId(UUID mediaId) {
        this.mediaId = mediaId;
    }
    public List<UUID> getTargetUsers() {
        return targetUsers;
    }
    public void setTargetUsers(List<UUID> targetUsers) {
        this.targetUsers = targetUsers;
    }
    public UUID getCommentId() {
        return commentId;
    }
    public void setCommentId(UUID commentId) {
        this.commentId = commentId;
    }  
}

this is the code for query the data


public List<UserActivityDto> getUserActivityByUserAndHisFriend(
            UUID user, long startId , UUID lastActivityId, int count) {
        // TODO Auto-generated method stub
        List<UUID> users = new Vector<UUID>() ;
        users.add(user) ;
        List<UserFriendShipDto> fsDtoLs = this.friendShipBo.getUserFriendsList(user, -1, Integer.MAX_VALUE) ;
        if(fsDtoLs != null && fsDtoLs.size()>0){
            for(UserFriendShipDto ufsd : fsDtoLs){
                users.add(ufsd.getFriendUserId()) ;
            }
        }
        String query = "" ;
        String [] param = null ;
        Object [] value = null ;
        if(startId == -1){
           
            query = " SELECT ua FROM " + UserActivity.class.getSimpleName() + " ua WHERE "
                    + " ua.key.userId IN :users ORDER BY ua.key.createdDate DESC";

           
            System.out.println("SELECT ua FROM " + UserActivity.class.getSimpleName() + " ua WHERE "
                    + " ua.key.userId IN (" + users.toString().replace("[", "").replace("]", "") +")");
            param = new String[]{"users"} ;
            value = new Object[]{users.toString().replace("[", "(").replace("]", ")")} ;
        }else{
            query = " SELECT ua FROM " + UserActivity.class.getSimpleName() + " ua WHERE "
                    + " ua.key.userId IN :users AND ua.key.createdDate <= :startId AND ua.key.id < :lastActivityId ORDER BY ua.key.createdDate DESC" ;
            param = new String[]{"users" , "startId" , "lastActivityId" } ;
            value = new Object[]{users.toString().replace("[", "(").replace("]", ")") , startId, lastActivityId} ;
        }
       
        List<UserActivity> listOfUserActivity = (List<UserActivity>) this.dao.findByQuery(query, param, value, count) ;


.......

i got the following exception on the bold line above.


javax.persistence.PersistenceException: javax.persistence.PersistenceException: InvalidRequestException(why:Order by on unknown column ua.key.createdDate)] with root cause
InvalidRequestException(why:Order by on unknown column ua.key.createdDate)
    at org.apache.cassandra.thrift.Cassandra$execute_cql3_query_result.read(Cassandra.java:37849)
    at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:78)
    at org.apache.cassandra.thrift.Cassandra$Client.recv_execute_cql3_query(Cassandra.java:1562)
    at org.apache.cassandra.thrift.Cassandra$Client.execute_cql3_query(Cassandra.java:1547)
    at com.impetus.client.cassandra.CassandraClientBase.executeCQLQuery(CassandraClientBase.java:1908)
    at com.impetus.client.cassandra.CassandraClientBase$CQLClient.executeQuery(CassandraClientBase.java:2096)
    at com.impetus.client.cassandra.CassandraClientBase.executeSelectQuery(CassandraClientBase.java:833)
    at com.impetus.client.cassandra.thrift.ThriftClient.executeQuery(ThriftClient.java:944)
    at com.impetus.client.cassandra.query.CassQuery.populateEntities(CassQuery.java:140)
    at com.impetus.kundera.query.QueryImpl.getResultList(QueryImpl.java:153)
    at com.audition.dao.impl.AuditionDaoImpl.findByQuery(AuditionDaoImpl.java:187)
    at com.audition.bo.impl.UserActivityBoImpl.getUserActivityByUserAndHisFriend(UserActivityBoImpl.java:103)
    at com.audition.rest.UserActivityRest.getUserAllUserAndFrindsActivityForUser(UserActivityRest.java:43)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:690)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)


is there is a way to fix this issue

thanks





Chhavi Gangwal

unread,
May 6, 2014, 12:13:13 AM5/6/14
to kundera...@googlegroups.com

Hi,

The issue is fixed  in the latest version of Kundera i.e. 2.11.1. Can you please try with that and see if the issue still persists.

Chhavi

Alaa Abu Zaghleh

unread,
May 7, 2014, 4:50:15 PM5/7/14
to kundera...@googlegroups.com
Hi ,
After I upgarte to 2.11 as you suggest to solve my order by issue.  I start getting this exception it is complettly in different part of the application

the table is defined as follows.

create table medias_by_id(
    type TEXT,
    id UUID ,
    title TEXT,
    description TEXT,
    pic_320X320 TEXT,
    pic_100X100 TEXT,
    pic_large TEXT,
    image_category UUID,
    user_id UUID,
    created_date BIGINT,
    like_count INT ,
    share_count INT,
    dislike_count INT,
    comment_count INT,
    view_count INT,
    rating FLOAT,
    rating_total FLOAT,
    number_of_raring INT,    
    video_file_name text,
    PRIMARY KEY(id)
) ;

and this is the java model for that table


import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

import com.audition.dao.model.key.ImagesByDateKey;
import com.impetus.kundera.index.IndexCollection;
import com.impetus.kundera.index.Index;

/**
 */
@Entity
@Table(name = "medias_by_id", schema = "auditionspace@auditionspace_pu")
//@IndexCollection(columns = { @Index(name = "created_by"), @Index(name = "image_category")})
@XmlRootElement(name = "imagesById")
public class ImagesById {
    @Id

    @Column(name="id")
    private UUID id ;
    @Column(name="type")
    private String type ;
    @Column(name="created_date")
    private long createdDate ;

    @Column(name="user_id")
    private UUID userId ;
    @Column(name="description")
    private String description ;
    @Column(name="pic_320x320")
    private String pic320X320 ;
    @Column(name="pic_100x100")
    private String pic100X100 ;
    @Column(name="pic_large")
    private String picLarge ;
    @Column(name="image_category")
    private UUID imageCategory ;
    @Column(name="like_count")
    private int likeCount ;
    @Column(name="share_count")
    private int shareCount ;
    @Column(name="dislike_count")
    private int dislikeCount ;
    @Column(name="rating")
    private float rating ;
    @Column(name="rating_total")
    private float raingTotal ;
    @Column(name="number_of_raring")
    private int numberOfRating ;
    @Column(name="title")
    private String title;
    @Column(name="comment_count")
    private int commentCount ;
    @Column(name="view_count")
    private int viewCount ;
    @Column(name="video_file_name")
    private String videoFileName;
   
    /**
     * Method getUserId.
     * @return UUID
     */

    public UUID getUserId() {
        return userId;
    }
    /**
     * Method setUserId.
     * @param userId UUID
     */

    public void setUserId(UUID userId) {
        this.userId = userId;
    }
    /**
     * Method getDescription.
     * @return String
     */
    public String getDescription() {
        return description;
    }
    /**
     * Method setDescription.
     * @param description String
     */
    public void setDescription(String description) {
        this.description = description;
    }
    /**
     * Method getPic320X320.
     * @return String
     */
    public String getPic320X320() {
        return pic320X320;
    }
    /**
     * Method setPic320X320.
     * @param pic320x320 String
     */
    public void setPic320X320(String pic320x320) {
        pic320X320 = pic320x320;
    }
    /**
     * Method getPic100X100.
     * @return String
     */
    public String getPic100X100() {
        return pic100X100;
    }
    /**
     * Method setPic100X100.
     * @param pic100x100 String
     */
    public void setPic100X100(String pic100x100) {
        pic100X100 = pic100x100;
    }
    /**
     * Method getPicLarge.
     * @return String
     */
    public String getPicLarge() {
        return picLarge;
    }
    /**
     * Method setPicLarge.
     * @param picLarge String
     */
    public void setPicLarge(String picLarge) {
        this.picLarge = picLarge;
    }
    /**
     * Method getImageCategory.
     * @return UUID
     */
    public UUID getImageCategory() {
        return imageCategory;
    }
    /**
     * Method setImageCategory.
     * @param imageCategory UUID
     */
    public void setImageCategory(UUID imageCategory) {
        this.imageCategory = imageCategory;
    }
    /**
     * Method getLikeCount.
     * @return int
     */
    public int getLikeCount() {
        return likeCount;
    }
    /**
     * Method setLikeCount.
     * @param likeCount int
     */
    public void setLikeCount(int likeCount) {
        this.likeCount = likeCount;
    }
    /**
     * Method getShareCount.
     * @return int
     */
    public int getShareCount() {
        return shareCount;
    }
    /**
     * Method setShareCount.
     * @param shareCount int
     */
    public void setShareCount(int shareCount) {
        this.shareCount = shareCount;
    }
    /**
     * Method getDislikeCount.
     * @return int
     */
    public int getDislikeCount() {
        return dislikeCount;
    }
    /**
     * Method setDislikeCount.
     * @param dislikeCount int
     */
    public void setDislikeCount(int dislikeCount) {
        this.dislikeCount = dislikeCount;
    }
    /**
     * Method getRating.
     * @return float
     */
    public float getRating() {
        return rating;
    }
    /**
     * Method setRating.
     * @param rating float
     */
    public void setRating(float rating) {
        this.rating = rating;
    }
    /**
     * Method getRaingTotal.
     * @return float
     */
    public float getRaingTotal() {
        return raingTotal;
    }
    /**
     * Method setRaingTotal.
     * @param raingTotal float
     */
    public void setRaingTotal(float raingTotal) {
        this.raingTotal = raingTotal;
    }
    /**
     * Method getNumberOfRating.
     * @return int
     */
    public int getNumberOfRating() {
        return numberOfRating;
    }
    /**
     * Method setNumberOfRating.
     * @param numberOfRating int
     */
    public void setNumberOfRating(int numberOfRating) {
        this.numberOfRating = numberOfRating;
    }
    /**
     * Method getTitle.
     * @return String
     */
    public String getTitle() {
        return title;
    }
    /**
     * Method setTitle.
     * @param title String
     */
    public void setTitle(String title) {
        this.title = title;
    }
    /**
     * Method getId.
     * @return UUID
     */

    public UUID getId() {
        return id;
    }
    /**
     * Method setId.
     * @param id UUID
     */

    public void setId(UUID id) {
        this.id = id;
    }
    /**
     * Method getCommentCount.
     * @return int
     */
    public int getCommentCount() {
        return commentCount;
    }
    /**
     * Method setCommentCount.
     * @param commentCount int
     */
    public void setCommentCount(int commentCount) {
        this.commentCount = commentCount;
    }
    /**
     * Method getViewCount.
     * @return int
     */
    public int getViewCount() {
        return viewCount;
    }
    /**
     * Method setViewCount.
     * @param viewCount int
     */
    public void setViewCount(int viewCount) {
        this.viewCount = viewCount;
    }
    /**
     * Method getType.
     * @return String
     */
    public String getType() {
        return type;
    }
    /**
     * Method setType.
     * @param type String
     */
    public void setType(String type) {
        this.type = type;
    }
    /**
     * Method getCreatedDate.
     * @return long
     */
    public long getCreatedDate() {
        return createdDate;
    }
    /**
     * Method setCreatedDate.
     * @param createdDate long
     */
    public void setCreatedDate(long createdDate) {
        this.createdDate = createdDate;
    }
    /**
     * Method VideoFileName.
     * @return String
     */
    public String getVideoFileName() {
        return videoFileName;
    }
    /**
     * Method VideoFileName.
     * @param videoFileName String
     */
    public void setVideoFileName(String videoFileName) {
        this.videoFileName = videoFileName;
    }
}


and this is how I get the data based on the id

@Override
    public ImageDto getOneImageById(UUID id) {

        // TODO Auto-generated method stub
        String query = "SELECT images FROM " + ImagesById.class.getSimpleName()
                + " images WHERE images.id= :id";

        List<ImagesById> ls = (List<ImagesById>) this.dao.findByQuery(query,
                "id", id);

        if (ls != null && ls.size() > 0) {
            ImageDto dto = new ImageDto();
            dto = this.convertImagesByIdToImageDto(ls.get(0), dto);
            UserDto user = this.userBo.getUserById(dto.getUserId());
            String userFirstName = user.getFirstName();
            String userLastName = user.getLastName();
            MediaCategoriesDto category = this.imageCategorybo
                    .getImageCategoryById(dto.getImageCategory());
            String categoryName = category.getCategoryDesc();
            dto.setCategoryName(categoryName);
            dto.setUserFirstName(userFirstName);
            dto.setUserLastName(userLastName);
            return dto;
        } else {
            return null;
        }
    }

the bold line is where my code is broking currently it was working fine in 2.9. (5b997526-5485-4ef9-94b2-f261daa53eea) is there in the table I can select it using CQLSH. I dont know what casuing this issue, any help will be highly appreciated.



[Request processing failed; nested exception is javax.persistence.PersistenceException: javax.persistence.PersistenceException: com.impetus.kundera.KunderaException: InvalidRequestException(why:Undefined name key in where clause ('key EQ token(5b997526-5485-4ef9-94b2-f261daa53eea)'))] with root cause
InvalidRequestException(why:Undefined name key in where clause ('key EQ token(5b997526-5485-4ef9-94b2-f261daa53eea)'))

    at org.apache.cassandra.thrift.Cassandra$execute_cql3_query_result.read(Cassandra.java:37849)
    at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:78)
    at org.apache.cassandra.thrift.Cassandra$Client.recv_execute_cql3_query(Cassandra.java:1562)
    at org.apache.cassandra.thrift.Cassandra$Client.execute_cql3_query(Cassandra.java:1547)
    at com.impetus.client.cassandra.CassandraClientBase.execute(CassandraClientBase.java:2291)
    at com.impetus.client.cassandra.CassandraClientBase.executeCQLQuery(CassandraClientBase.java:1860)
    at com.impetus.client.cassandra.CassandraClientBase$CQLClient.executeQuery(CassandraClientBase.java:2028)
    at com.impetus.client.cassandra.CassandraClientBase.executeSelectQuery(CassandraClientBase.java:854)
    at com.impetus.client.cassandra.thrift.ThriftClient.executeQuery(ThriftClient.java:906)
    at com.impetus.client.cassandra.query.CassQuery.populateEntities(CassQuery.java:135)
    at com.impetus.kundera.query.QueryImpl.fetch(QueryImpl.java:927)
    at com.impetus.kundera.query.QueryImpl.getResultList(QueryImpl.java:157)
    at com.audition.dao.impl.AuditionDaoImpl.findByQuery(AuditionDaoImpl.java:143)
    at com.audition.bo.impl.ImageBoImpl.getOneImageById(ImageBoImpl.java:520)
    at com.audition.bo.impl.UserActivityBoImpl.getUserActivityByUserAndHisFriend(UserActivityBoImpl.java:111)
Reply all
Reply to author
Forward
0 new messages