gpt4 book ai didi

java - hibernate注释类中出现错误

转载 作者:行者123 更新时间:2023-12-02 02:50:25 27 4
gpt4 key购买 nike

当我使用时,我的 hibernate 程序出现错误我的 bean 类中的注释,并且我在 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>

最佳答案

使用来自LeaveStatus而不是来自current_leave

关于java - hibernate注释类中出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43934688/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com