Mysql query in java -
i have service rest database generated in netbeans. creates entity classes each table .
@entity @table(name = "users") @xmlrootelement @namedqueries({ @namedquery(name = "users.findall", query = "select u users u"), @namedquery(name = "users.findbyid", query = "select u users u u.id = :id"), @namedquery(name = "users.findbyname", query = "select u users u u.name = :name"), @namedquery(name = "users.findbytelephone", query = "select u users u u.telephone = :telephone"), @namedquery(name = "users.findbyyear", query = "select u users u u.year = :year")}) public class users implements serializable { private static final long serialversionuid = 1l; @id @basic(optional = false) @notnull @column(name = "id") private integer id; @size(max = 25) @column(name = "name") private string name; @column(name = "telephone") private integer telephone; @column(name = "year") private integer year; public users() { } public users(integer id) { this.id = id; } public integer getid() { return id; } public void setid(integer id) { this.id = id; } public string getname() { return name; } public void setname(string name) { this.name = name; } public integer gettelephone() { return telephone; } public void settelephone(integer telephone) { this.telephone = telephone; } public integer getyear() { return year; } public void setyear(integer year) { this.year = year; } @override public int hashcode() { int hash = 0; hash += (id != null ? id.hashcode() : 0); return hash; } @override public boolean equals(object object) { // todo: warning - method won't work in case id fields not set if (!(object instanceof users)) { return false; } users other = (users) object; if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { return false; } return true; } @override public string tostring() { return "glee.users[ id=" + id + " ]"; }
how can query db class another? ? example select : select name
bb.users; , save in array eg thanks
@namedquery(name,query)
annotation used hard code queries persistence class. can retrievequery
usingname
attribute specified.when using hibernate session, can use getnamedquery query.
when used entitymanager can use createnamedquery.
both of retrieve query , and can execute query basic query operations.
list users = session.getnamedquery("users.findbyid").setparameter("id", "1").list();
Comments
Post a Comment