gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:08:02 25 4
gpt4 key购买 nike

我很难找到与 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 上的标识符更改组合键,但出现了同样的错误你知道会发生什么吗?我应该以不同的方式声明加入吗?

最佳答案

使用 mappedBy 注释修复。 @OneToMany(cascade = CascadeType.ALL, mappedby = "objKey.strObjectGUID")

关于java - Hibernate 无法找到具有逻辑名称的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54518668/

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