Solved

Jpa query

Posted on 2014-04-28
2
181 Views
Last Modified: 2014-05-11
Let me know how to write a sql  through jpa annotation

I have  to find a single value column through jpa here is the sql statement
select userkey from right table where code = + code

Open in new window

0
Comment
Question by:roy_sanu
  • 2
2 Comments
 
LVL 20

Expert Comment

by:chaitu chaitu
Comment Utility
make the class as Entity and on top of that write named queries.

@Entity
@Table(name="A")
@NamedQuery(name="selectUser",query="select userkey from right table where code = :code")
public class A implements java.io.Serializable{
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private Long id;


write other variables...
}


call this query like this.

Query query = em.createNamedQuery("selectUser");
            query.setParameter("code", 1234);
            List<String> resultList = (List<String>) query.getResultList();
0
 
LVL 20

Accepted Solution

by:
chaitu chaitu earned 500 total points
Comment Utility
or you can do like this..

String num = (String) em.createQuery("select userkey from right table where code = :code").setParameter("code",1234) .getSingleResult();
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now