Posts Tagged JPA
The purpose of this video is to explain a scenario which shows the way how to create a database project using an object oriented approach. Rational Software Architect and Rational Data Architect (Infosphere Data Architect) are used for this tutorial. Using RDA and RSA you may watch this simple tutorial about creating a logical model. After that, converting it to a physical model. The third step will be creating the database, and after that creating the entities mapped with the database. With a sample web application, these entities are used and tested.
Assume that your database you have a “News” table and a “Comment” table. In your Java entities you have mapped the News and the Comment table as two classes. Different users post comments to your News and you need to display these comments and the web page were the News is displayed. So, the first operation to be done is to sort them according to the post date. You don’t need to write a query for it. Just take the comment collection of that specific news and use the @OrderBy annotation in order to sort.
private List<Comment> commentCollection;
News news = … //Here you get your news object
List<Comment> comments = news.getCommentCollection(); //By this operation you accomplish the ordering of the comments shown to the news
In @OrderBy(“POSTDATE ASC”) the POSTDATE is an attribute of the table of Comments.