如何解决因继承 class 而导致的 org.hibernate.MappingException

How to solve org.hibernate.MappingException which is causing due to inheriting a class

最近我将我的项目从 Hibernate 版本 3.1 迁移到 4.3,为了获得更好的性能,我尝试使用注释而不是我的 xml mapping.I 在所有实体 [=32] 中都有以下异常=] 我继承了一个 class.The 错误是“ org.hibernate.MappingException”

我尝试将 targetEntity 添加到 manytoOne class 并添加 @Access(AccessType.PROPERTY) 没有任何效果。更改为字段注释是不可能的,因为我有 150 多个实体 class。我试图删除扩展 class,它的 @override 方法和异常不存在,但是,我需要添加使用它。

这是我的实体class

    @Entity
    @Table(name = "mapusergroups", catalog = "designdb")
    public class Mapusergroups extends PlanroomMigrationEntity implements 
    java.io.Serializable {

private int idMapUserGroups;
private Groups groups;
private Users users;

public Mapusergroups() {
}

public Mapusergroups(Groups groups, Users users) {
    this.groups = groups;
    this.users = users;
}

@Id
@GeneratedValue(strategy = IDENTITY)

@Column(name = "idMapUserGroups", unique = true, nullable = false)
public int getIdMapUserGroups() {
    return this.idMapUserGroups;
}

public String getIdMapUserGroupsString() {
    return "" + this.idMapUserGroups;
}

public void setIdMapUserGroups(int idMapUserGroups) {
    this.idMapUserGroups = idMapUserGroups;
}

@ManyToOne(fetch = FetchType.LAZY, targetEntity = Groups.class)
@JoinColumn(name = "FK_idGroups", nullable = false)
@PlanroomMigrationEntity.PathUpToCompany
public Groups getGroups() {
    return this.groups;
}

public void setGroups(Groups groups) {
    this.groups = groups;
}

@ManyToOne(fetch = FetchType.LAZY, targetEntity = Users.class)
@JoinColumn(name = "FK_idUsers", nullable = false)
@PlanroomMigrationEntity.ReferenceToUser
public Users getUsers() {
    return this.users;
}

public void setUsers(Users users) {
    this.users = users;
}

@Override
public BaseWrapper<?> getWrapper() {
    return new WMapUserGroups(this);
}

@Override
public PlanroomMigrationDAO getDao() {
    return new MapUserGroupsDAO();
}

@Override
public void attachReferences(JSONObject json, ObjectFinder finder)
        throws JSONException {      this.users = json.has("userId") ? (Users) finder.lookup(Users.class,
json.get("userId").toString()) : null;
this.groups = json.has("groupId") ? (Groups) finder.lookup(
        Groups.class, json.get("groupId").toString()) : null;
}

这是我的xml,用于转换为注释

   @XmlType
   public class Mapusergroups extends PlanroomMigrationEntity implements
    java.io.Serializable {

private int idMapUserGroups;
private Users users;
private Groups groups;

public Mapusergroups() {
}

@Deprecated
public Mapusergroups(Users users, Groups groups) {
    this.users = users;
    this.groups = groups;
}

@XmlAttribute
public int getIdMapUserGroups() {
    return this.idMapUserGroups;
}

@XmlAttribute
@XmlID
public String getIdMapUserGroupsString() {
    return "" + this.idMapUserGroups;
}

public void setIdMapUserGroups(int idMapUserGroups) {
    this.idMapUserGroups = idMapUserGroups;
}

@XmlAttribute
@XmlIDREF
@PlanroomMigrationEntity.ReferenceToUser
public Users getUsers() {
    return this.users;
}

public void setUsers(Users users) {
    this.users = users;
}

@XmlAttribute
@XmlIDREF
@PlanroomMigrationEntity.PathUpToCompany
public Groups getGroups() {
    return this.groups;
}

public void setGroups(Groups groups) {
    this.groups = groups;
}

@Override
public BaseWrapper<?> getWrapper() {
    return new WMapUserGroups(this);
}

@Override
public PlanroomMigrationDAO getDao() {
    return new MapUserGroupsDAO();
}

@Override
public void attachReferences(JSONObject json, ObjectFinder finder)
        throws JSONException {
    this.users = json.has("userId") ? (Users) finder.lookup(Users.class,
            json.get("userId").toString()) : null;
    this.groups = json.has("groupId") ? (Groups) finder.lookup(
            Groups.class, json.get("groupId").toString()) : null;
}

我需要使用带有 属性 注释的 PlanroomMigrationEntity。请帮忙。

这是我的堆栈跟踪

org.hibernate.MappingException: Could not determine type for: com.at.project.service.planroom_migration.PlanroomMigrationDAO, at table: mapusergroups, for columns: [org.hibernate.mapping.Column(dao)] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:349) at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:322) at org.hibernate.mapping.Property.isValid(Property.java:241) at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:496) at org.hibernate.mapping.RootClass.validate(RootClass.java:270) at org.hibernate.cfg.Configuration.validate(Configuration.java:1360) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1851) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930) at wadetech.DB.base.HibernateUtils.(HibernateUtils.java:111) at wadetech.DB.base.BaseDAO.(BaseDAO.java:43) at wadetech.DB.DAOS.__MaintenanceDAO.(__MaintenanceDAO.java:10) at com.at.project.utils.runtime.RuntimeModifier.HasExecuted(RuntimeModifier.java:127) at wadetech.listeners.ModificationScriptStartupListener.contextInitialized(ModificationScriptStartupListener.java:47) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5016) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5528) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745)

跟继承关系不大。阅读错误消息。它说 Hibernate 不知道如何映射 属性 dao 类型 PlanroomMigrationDAO 您的实体。

这个 属性 首先不应该存在:一个实体不应该负责创建 DAO。

但是如果你真的想坚持那个设计,你需要告诉 JPA dao 不是持久化的属性。这就是 @Transient 注释的作用。