-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Correct way to use an Enumerated ordinal in a query ?
PostPosted: Wed May 23, 2012 12:19 pm 
Newbie

Joined: Mon Jan 21, 2008 12:38 pm
Posts: 3
Ive searched and searched for an answer to this but still cannot solve..

I know it will work if I pass the enum value to the hql query as a param but how can I hardcode the enum in the query like the following?

(this is groovy code, so thats why theres no ;'s or double quotes )

I assume the enum does not have to be backed by a table or exist in persistence.xml.
im using @Enumerated in my entity - should i be using embeddable ? or something else ????


[b]@NamedQuery(name = 'CategoryItemEvent.userPassport',
query = 'SELECT o FROM CategoryItemEvent o WHERE \
o.user = :user and \
o.categoryItem.category.id = 1 AND \
o.categoryItemEventType = com.xxx.ql.entity.CategoryItemEventTypeName.HATE')[/b]


enum:

public enum CategoryItemEventTypeName {
REVIEW(1),
STAY(2),
STAYED_AND_LIKED(3),
BOOK(4),
CHECKIN(5),
PHOTO(6),
MESSAGE_PUBLIC(7),
MESSAGE_PRIVATE(8),
CITY_QUESTION(9),
CITY_QUESTION_COMMENT(10),
CITY_COMMENT(11),
CITY_ANSWER(12),
CITY_DEAL(13),
HOTEL_QUESTION(14),
HOTEL_ANSWER(15),
HOTEL_QUESTION_COMMENT(16),
HOTEL_COMMENT(17),
HOTEL_DEAL(18),
GROUP_DEAL(19),
LIKE(20),
LOVE(21),
DISLIKE(22),
HATE(23)


final Long id

private CategoryItemEventTypeName(Long id) {
this.id = id
}


}

Entity:

public class CategoryItemEvent implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id

@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name='itemId')
CategoryItem categoryItem

@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name='itemId', insertable = false, updatable=false)
CategoryHotel categoryHotel

[b] @NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "typeId")
@Enumerated
CategoryItemEventType categoryItemEventType[/b]

@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "userId")
User user

@NotBlank
String text

@OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
@JoinTable(
name = "ql_category_item_event2context",
joinColumns = [@JoinColumn(name = "eventId")],
inverseJoinColumns = [@JoinColumn(name = "contextId")]
)
List<CategoryItemEventContext> contexts

@NotNull
Date createDate

Integer sentiment

@OneToOne(cascade = CascadeType.ALL, mappedBy = "event", fetch = FetchType.LAZY)
ImportTaReviewsIds importTaReviewsIds;
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.