Hibernate无法找到具有逻辑名称的列

时间:2019-02-04 14:49:59

标签: java hibernate

我很难找到与Hibernate的列映射有关的错误。我在SQL上存储了几个应用程序的信息,每个应用程序可能具有一个或多个插件。解决了应用程序和插件之间的关系,没有任何问题。但是,作为第二种关系,外接程序可能具有多个属性。 我只是在下面出现错误的地方添加对象

@Embeddable
public class PropertyKey implements Serializable
{
    /**
     * 
     */
    private static final long serialVersionUID = -7240987531179265668L;
    private String strObjectGUID;
    private String strValue;
}
@Entity
@Table(name = "tbl_properties")
public class PropertyEntity
{
    @EmbeddedId
    private PropertyKey objKey;
}
@Entity
@Table(name = "tbl_addins")
public class AddInEntity
{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "intCode")
    private Integer intCode;
    private String strID;
    private String strApplicationID;
    private String strType;
    @OneToMany(cascade = CascadeType.ALL)
    @JoinColumn(name = "strObjectGUID", referencedColumnName = "strPropertyID")
    private List<PropertyEntity> colProperties;
}

我收到的错误是:

[main] INFO com.mchange.v2.c3p0.C3P0Registry - Initializing c3p0-0.9.5.2 [built 08-December-2015 22:06:04 -0800; debug? true; trace: 10]
[main] INFO com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource - Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@b781de3a [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@ed59c9fa [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, identityToken -> 2ssjxha01fbizdoddf7pr|38eb2c50, idleConnectionTestPeriod -> 3000, initialPoolSize -> 5, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 300, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 1000, maxStatements -> 1000, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@4c881e72 [ description -> null, driverClass -> null, factoryClassLocation -> null, forceUseNamedDriverClass -> false, identityToken -> 2ssjxha01fbizdoddf7pr|5411dd90, jdbcUrl -> jdbc:sqlserver://localhost, properties -> {databasename=Azure, integratedsecurity=true} ], preferredTestQuery -> null, privilegeSpawnedThreads -> false, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, extensions -> {}, factoryClassLocation -> null, identityToken -> 2ssjxha01fbizdoddf7pr|23202c31, numHelperThreads -> 3 ]
Initial SessionFactory creation failed.org.hibernate.AnnotationException: Unable to map collection azure.entities.AddInEntity.colProperties
Monday, 4 Feb 2019 11:42:46 AM [main] ERROR azure.hibernate.HibernateUtil - Initial SessionFactory creation failed
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: org.hibernate.AnnotationException: Unable to map collection azure.entities.AddInEntity.colProperties
Caused by: org.hibernate.cfg.RecoverableException: Unable to find column with logical name: strPropertyID in org.hibernate.mapping.Table(tbl_addins) and its related supertables and secondary tables
Caused by: org.hibernate.MappingException: Unable to find column with logical name: strPropertyID in org.hibernate.mapping.Table(tbl_addins) and its related supertables and secondary tables

此对象的SQL模式为:

CREATE TABLE tbl_properties
(
    strObjectGUID nvarchar(36) NOT NULL,
    strValue nvarchar(MAX)
    CONSTRAINT pk_properties PRIMARY KEY (strObjectGUID)
)
CREATE TABLE tbl_addins
(
    intCode int NOT NULL IDENTITY(1, 1),
    strID nvarchar(36) NOT NULL,
    strApplicationID nvarchar(36) NOT NULL,
    strType nvarchar(MAX),
    strPropertyID nvarchar(36)
    CONSTRAINT pk_addins PRIMARY KEY (intCode),
    CONSTRAINT fk_addins_properties FOREIGN KEY (strPropertyID) REFERENCES tbl_properties(strObjectGUID),
    CONSTRAINT fk_addins_applications FOREIGN KEY (strApplicationID) REFERENCES tbl_applications(strObjectGUID)
)

我尝试通过PropertyEntity上的标识符更改组合键,但是发生相同的错误 您对可能发生的事情有任何想法吗?我应该以其他方式声明加入吗?

2 个答案:

答案 0 :(得分:0)

根据@JoinColumn documentation

name用于当前表的列 referencedColumnName用于设置联接表的列。

在您的情况下,您需要将config替换为:

@JoinColumn(name = "strPropertyID", referencedColumnName = "strObjectGUID")

答案 1 :(得分:0)

使用mappedBy注解修复。 @OneToMany(级联= CascadeType.ALL,mappedby =“ objKey.strObjectGUID”)

相关问题