Reputation: 23
I am getting an error in my hibernate programme as I used the annotation in my bean class and I added the mapping class in the hibernate.cfg.xml
org.hibernate.hql.internal.ast.QuerySyntaxException: current_leave is not mapped
main class is having files of connection
final Configuration configuration = new Configuration().configure(HibernateCfgUrls.MYSQL_CFG);
final StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties());
final SessionFactory factory = configuration.buildSessionFactory(builder.build());
final Session session = factory.openSession();
String hqlQuery = "from current_leave";
Query query = session.createQuery(hqlQuery);
List<LeaveStatus> listCategories = query.list();
for (LeaveStatus list : listCategories) {
System.out.println("===============");
System.out.println("Employee id" + list.getStartDate());
System.out.println("Employee name" + list.getEndDate());
System.out.println("Employee address" + list.getLeaveName());
System.out.println("Employee address" + list.getComments());
}
leaveStatus.java it is the pojo class
package com.bizee.bean;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.SecondaryTable;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@Entity
@Table(name = "current_leave")
public class LeaveStatus
{
@Column(name = "start_date", table= "current_leave")
private Date startDate;
@Column(name = "end_date", table= "current_leave")
private Date endDate;
@Column(name = "comments", table= "current_leave")
private String comments;
@Column(name = "leave_id", table= "current_leave")
private int leaveName;
public LeaveStatus() {
// TODO Auto-generated constructor stub
}
public LeaveStatus(Date startDate, Date endDate, String comments, int leaveName) {
super();
this.startDate = startDate;
this.endDate = endDate;
this.comments = comments;
this.leaveName = leaveName;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}
public int getLeaveName() {
return leaveName;
}
public void setLeaveName(int leaveName) {
this.leaveName = leaveName;
}
}
hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://xxx.xxx.xx.xx:xxxx/abc_hrms</property>
<property name="connection.username">xxxxx</property>
<property name="connection.password">xxxxxxxxxxx</property>
<property name="connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<property name="format_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping resource="com/bizee/bean/employeeHBM.xml" />
<mapping class = "com.bizee.bean.LeaveStatus"/>
<!-- <mapping class = "com.bizee.bean.EmployeeDemo"/> -->
</session-factory>
</hibernate-configuration>
Upvotes: 0
Views: 204
Reputation: 23
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/leaveservice] threw exception [Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;] with root cause
java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
Upvotes: 0