【问题标题】:Grails domain mapping exceptionGrails 域映射异常
【发布时间】:2015-10-09 01:56:00
【问题描述】:

运行良好后,我的应用程序在启动时开始出现奇怪的域错误。无论我做什么,我都无法让它发挥作用。

Caused by MappingException: Could not determine type for: appospherelaunchv1.Entity, at table: entity_history, for columns: [org.hibernate.mapping.Column(entity)]

EntityHistory 类:

    class EntityHistory {
    Entity entity
    Date startDate
    Date endDate
    Boolean isCurrent
    Date changeDate

   static belongsTo = [entity: Entity]

   static constraints = {
        entityTypeID nullable:false
        startDate nullable:false
        endDate nullable:true
        changeDate nullable:false
        isCurrent nullable:true
   }
}

实体类:

class Entity {
String description
Date changeDate
Date createDate
Date entityChangeDate
EntityTypes entityTypes
User user
Customer customer
Contacts contacts
LeadSources leadSources
EntityStatus entityStatus

static hasMany = [entityData: EntityData]
static belongsTo = [entityTypes: EntityTypes, user: User, customer: Customer, contacts: Contacts, leadSources: LeadSources, entityStatus: EntityStatus]

   static constraints = {
        user nullable:false
        customer nullable:false
        contacts nullable:false
        leadSources nullable:false
        description size:1..2000, nullable:true
        entityTypes nullable:false
        changeDate nullable:false
        createDate nullable:false
        entityStatus nullable: false
        }
}

删除属于实体关系不会更改错误消息。有没有人见过这个错误?

【问题讨论】:

  • 您可以尝试在新的数据库实例中创建吗?
  • 根据我的经验,如果您在belongsTo 中定义了实体,您也不必单独显式定义它。如果您将Entity entity 保留在您的EntityHistory 域中,则只需声明belongsTo = Entity。如果您删除Entity entity,您可以保留belongsTo = [entity: Entity]。但是,既然您说完全删除 belongsTo 并不能解决问题,这可能没有帮助。
  • 运行良好奇怪的域错误之间发生了什么?

标签: hibernate grails grails-orm grails-domain-class


【解决方案1】:

我猜如果您已经在 EntityHistorybelongsTo 中定义了属性,那么就不需要定义与另一个属性相同的属性了。

因此请尝试从 EntityHistory 类中删除 Entity 实体,因为它无法将同名属性与您在数据库中的列映射。

它也可能已经搞砸了您的数据库。尝试在 DataSource 中使用“创建”模式在新数据库实例中运行您的应用程序,以创建新表。

谢谢。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-20
    • 1970-01-01
    • 1970-01-01
    • 2022-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多