is not mapped/No result defined for action

前言

使用Hibernate 报错

Caused by: org.hibernate.hql.ast.QuerySyntaxException: FeeOrganizationsDO is not mapped [FROM FeeOrganizationsDO ]

com.opensymphony.xwork2.config.ConfigurationException: No result defined for action

原因

检查了SQL语句没问题,大多数问题出在SQL

    @Override
    public List<FeeOrganizationsDO> queryAllByParam(FeeDetailParam param) {
        //创建条件
        try {
        //大多数人会错在这个地方 使用实体类名称 条件也用实体类字段 不要用数据库名称字段
            String sql = "FROM FeeOrganizationsDO where id=? ";
             List<FeeOrganizationsDO> feeOrganizationsDOS = dao.findByHql(DataSource.JW, DatabaseHandleMode.MASTER, sql, new Object[]{1});
            return feeOrganizationsDOS;
        } catch (Exception e) {
            throw new ServiceException("queryAllByParam error" + e.getMessage(), e);
        }
    }

原因

既然报错 一个映射问题,那说明实体类有问题
原因:没有@Entity,导致报错,@Data没用
@Entity定义对象将会成为被JPA管理的实体,将映射到指定的数据库表。
注意导包import javax.persistence.Entity;导错了就是如下错误
巨坑检查无误还报错is not mapped MappingException: Unknown entity:@Entity

@Getter
@Setter
@Entity
@Table(name="fee_organizations")
public class FeeOrganizationsDO implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     *ID
     */
    @Id
    @Column(name="id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
 }

延伸报错

延伸一下什么情况会触发is not mapped

SQL

写数据库名,或者实体类名写错都会报错,包括查询参数也要写实体类的

            String sql = "delete from  FeeBusinessHolidayDateDO where id = ?";
            String sql2 = "delete from  FeeHolidayDateDO where id = ?";

导包

import org.hibernate.annotations.Entity;✓
import javax.persistence.Entity;×

注解

不写@Entity扫描不到 报错

    @Entity
    @Id
    @Column(name = "id", nullable = false)
    @GeneratedValue(strategy = GenerationType.AUTO)

扫描

Hibernate.cfg.xml

待续

posted @ 2025-07-11 12:32  HezhezhiyuLe  阅读(7)  评论(0)    收藏  举报