Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPA CriteriaQuery MD5
JPA CriteriaQuery MD5 [message #1006338] Wed, 30 January 2013 21:41 Go to next message
Super User is currently offline Super UserFriend
Messages: 9
Registered: January 2013
Junior Member
Greetings,

Could somebody help to translate similar native query text to CriteriaQueriy code?

select tmp from tbl  
(select * from db_emails where folder="spam") tmp
where tmp.digest=md5(concat("digest",?))


Thanks in advance,
Re: JPA CriteriaQuery MD5 [message #1007347 is a reply to message #1006338] Tue, 05 February 2013 15:30 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

This would probably be better as a native SQL query, as it is complex and data specific.

The Criteria API does not support sub-selects in the from clause, so you would need to reword the query. To call the MD5 function you can use the function() API in Criteria.

What is your object model?


James : Wiki : Book : Blog : Twitter
Re: JPA CriteriaQuery MD5 [message #1007750 is a reply to message #1007347] Thu, 07 February 2013 12:04 Go to previous message
Super User is currently offline Super UserFriend
Messages: 9
Registered: January 2013
Junior Member
Greetings Mr. Sutherland,
Thank you for you answer.
I use simplest object model here:
@Entity
@Table(name = "db_emails")
class Email implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @Column(name = "title")    
    private String title;
    @Column(name = "from")    
    private String from;
    @Column(name = "to")
    private String to;
    @Column(name = "content")    
    private String content;
    @Column(name = "digest")
    private String digest;
/*
Getters and setters are being declared here

*/

}


It looks I made misprint in topic start message. Query I'm rtying to make with CriteriaQueries is about quering same table twice
select tmp from db_emails  
(select * from db_emails where folder="spam") tmp
where tmp.digest=md5(concat("digest",?))



Thanks in advance,

[Updated on: Mon, 11 February 2013 18:53]

Report message to a moderator

Previous Topic:OutOfMemoryError from JTASynchronizationListener
Next Topic:eclipselink flush mode out of memory
Goto Forum:
  


Current Time: Sat Mar 30 06:32:34 GMT 2024

Powered by FUDForum. Page generated in 0.07670 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top