I have already gone thru that tutorial. . I wanted to call an existing SP which is already stored in the database(MySQL) not to create anything. Is it possible?.I tried it in the following way. But it gave me an error saying " 13:16:56,292 ERROR PARSER:56 - line 1:1: unexpected token: call
Initial SessionFactory creation failed.java.lang.IllegalArgumentException: node to traverse cannot be null!" in the log.
Here are my codes:
Code for the entity-----
Code:
@Entity
@Table(name="tbl_customer")
@NamedQuery( name = "getCustomer",query = "call getCustomer_sp(:cid)")
public class Customer {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="id")
private int id;
@Column(name="first_name")
private String firstName;
@Column(name="last_name")
private String lastName;
@OneToOne(cascade=CascadeType.ALL)
//@Column(name="address_id")
private Address address;
@OneToMany(mappedBy="customer",targetEntity=Order.class,cascade=CascadeType.ALL)
private List<Order> orders = new ArrayList<Order>();
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public List<Order> getOrders() {
return orders;
}
public void setOrders(List<Order> orders) {
this.orders = orders;
}
@Override
public String toString() {
return firstName + " " + lastName;
}
}
My CustomerDAOImpl class where i want to use the SP
Code:
public class CustomerDAOImpl implements CustomerDAO {
@Override
public Customer getCustomer(int id) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
return (Customer)session.getNamedQuery("getCustomer").setParameter(0, id).uniqueResult();
}
}
I have configured my Customer Entity class in hibernateconfig.xml
Everything worked properly until i insert the @NamedQuery part to my Customer class. Where did I go wrong?
Please help me :(