gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 05:31:09 25 4
gpt4 key购买 nike

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

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

这是我的实体类

    @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 不知道如何映射实体的 PlanroomMigrationDAO 类型的属性 dao

这个属性一开始就不应该存在:实体不应该负责创建 DAO。

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

关于java - 如何解决由于继承类而导致的org.hibernate.MappingException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57527431/

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