如何解决由于继承类而导致的org.hibernate.MappingException

时间:2019-08-16 15:36:45

标签: java hibernate orm annotations mapping

最近我将我的项目从Hibernate 3.1版迁移到4.3,为了获得更好的性能,我尝试使用注释而不是xml映射。在继承类的所有实体类中都有以下异常。错误是“ org.hibernate.MappingException”

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

这是我的实体类

           for i in range(0,len(resultpath)):
                copy_source = {
                    'Bucket': bucketname,
                    'Key': resultpath[i]  #not sure if a list is OK
                }


            copy_source = {
                'Bucket': bucketname,
                'Key': {
                    'Objects':resultpath
                }
            }

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

    @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;
}

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

这是我的堆栈跟踪

  
    

org.hibernate.MappingException:无法确定com.at.project.service.planroom_migration.PlanroomMigrationDAO的类型,位于     表:mapusergroups,用于列:[org.hibernate.mapping.Column(dao)]       在org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:349)       在org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:322)       在org.hibernate.mapping.Property.isValid(Property.java:241)处     org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:496)       在org.hibernate.mapping.RootClass.validate(RootClass.java:270)处     org.hibernate.cfg.Configuration.validate(Configuration.java:1360)在     org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1851)       在     org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930)       在wadetech.DB.base.HibernateUtils。(HibernateUtils.java:111)       在wadetech.DB.base.BaseDAO。(BaseDAO.java:43)在     wadetech.DB.DAOS .__ MaintenanceDAO。(__ MaintenanceDAO.java:10)在     com.at.project.utils.runtime.RuntimeModifier.HasExecuted(RuntimeModifier.java:127)       在     wadetech.listeners.ModificationScriptStartupListener.contextInitialized(ModificationScriptStartupListener.java:47)       在     org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5016)       在     org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5528)       在     org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)       在     org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1575)       在     org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1565)       在java.util.concurrent.FutureTask.run(FutureTask.java:262)在     java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)       在     java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)       在java.lang.Thread.run(Thread.java:745)

  

1 个答案:

答案 0 :(得分:1)

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

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

但是,如果您真的想坚持这种设计,则需要告诉JPA dao不是持久属性。这就是@Transient批注的角色。