ceyesuma -4 Posting Pro


Topic
The topic of this question is: How does the @NamedQuery work?
Hello and Thank you in advance for any assistance.

Purpose:



The purpose of this code is understand why the Netbeans ide constructed @NamedQueries that refer to an object Content (the name of the Entity class ) when the table is named content.




Description



Code description: Then named Queries created by the ide.

@Entity
@Table(name = "content")
@NamedQueries({@NamedQuery(name = "Content.findAll", query = "SELECT c FROM Content c"), @NamedQuery(name = "Content.findById", query = "SELECT c FROM Content c WHERE c.id = :id"), @NamedQuery(name = "Content.findByPublisherCode", query = "SELECT c FROM Content c WHERE c.publisherCode = :publisherCode"), @NamedQuery(name = "Content.findByBookIsbn", query = "SELECT c FROM Content c WHERE c.bookIsbn = :bookIsbn"), @NamedQuery(name = "Content.findByBookTitle", query = "SELECT c FROM Content c WHERE c.bookTitle = :bookTitle"), @NamedQuery(name = "Content.findByArtist", query = "SELECT c FROM Content c WHERE c.artist = :artist"), @NamedQuery(name = "Content.findBySong", query = "SELECT c FROM Content c WHERE c.song = :song"), @NamedQuery(name = "Content.findByPageNum", query = "SELECT c FROM Content c WHERE c.pageNum = :pageNum")})
public class Content implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Column(name = "publisher_code")
    private String publisherCode;
    @Column(name = "book_isbn")
    private String bookIsbn;
    @Column(name = "book_title")
    private String bookTitle;
    @Column(name = "artist")
    private String artist;
    @Column(name = "song")
    private String song;
    @Column(name = "page_num")
    private Integer pageNum;

    public Content() {
    }



Description



Code description: I changed the @namedQueries to this. I did not make any difference

@Entity
@Table(name = "content")
@NamedQueries({@NamedQuery(name = "content.findAll", query = "SELECT c FROM content c"), @NamedQuery(name = "content.findById", query = "SELECT c FROM content c WHERE c.id = :id"), @NamedQuery(name = "content.findByPublisherCode", query = "SELECT c FROM content c WHERE c.publisherCode = :publisherCode"), @NamedQuery(name = "content.findByBookIsbn", query = "SELECT c FROM content c WHERE c.bookIsbn = :bookIsbn"), @NamedQuery(name = "content.findByBookTitle", query = "SELECT c FROM content c WHERE c.bookTitle = :bookTitle"), @NamedQuery(name = "content.findByArtist", query = "SELECT c FROM content c WHERE c.artist = :artist"), @NamedQuery(name = "content.findBySong", query = "SELECT c FROM content c WHERE c.song = :song"), @NamedQuery(name = "content.findByPageNum", query = "SELECT c FROM content c WHERE c.pageNum = :pageNum")})
public class Content implements Serializable {


Thanks again.
-ceyesuma




Solution:



The solutions related to this code are




Note:



Note:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.