java - 休眠无法找到具有逻辑名称的列
问题描述
我很难找到与 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")
推荐阅读
- javascript - Bootsrap 按钮在 React 中无法正常工作
- javascript - 将左标签推到桑基图中节点的左侧
- python - 如何在文件列表中为文件夹中的所有文件添加前缀“_”[Python]
- javascript - 获取购物车中物品的价值并相应地移除库存
- r - 从文件列表中读取 CSV 并“变异”一列(日期)
- c++ - 如何正确释放动态内存
- angular-material - 如何在 Angular 8 中的 Material Angular 中创建持续时间选择器
- python - pip 安装问题
- kubernetes - skaffold/kaniko:从另一个命名空间访问服务
- mysql - 将数据库存储在 /var/lib/docker/volumes/ 中有多安全?