我一直在努力解决这个错误一段时间,我无法在互联网上找到任何类似于我尝试编写的xml orm配置的内容。我认为这是因为它不是一件非常简单的事情。
错误:
[EL Warning]: 2017-02-18 00:53:51.747--UnitOfWork(2126751933)--Thread(Thread[main,5,main])--Exception [EclipseLink-45] (Eclipse Persistence Services - 2.6.2.v20151217-774c696): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Missing mapping for field [ordinary_user_account.id].
Descriptor: RelationalDescriptor(com.projects.simpleaccount.account.authorizationmanageableaccount.AuthorityScope --> [DatabaseTable(ordinary_user_account)])
FAILED: testSingleSave
org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Exception [EclipseLink-45] (Eclipse Persistence Services - 2.6.2.v20151217-774c696): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Missing mapping for field [ordinary_user_account.id].
Descriptor: RelationalDescriptor(com.projects.simpleaccount.account.authorizationmanageableaccount.AuthorityScope --> [DatabaseTable(ordinary_user_account)])
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:526)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:487)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:122)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy18.save(Unknown Source)
at com.projects.identityaccess.infrastructure.DefaultSpringOrdinaryUserAccountRepositoryTest.testSingleSave(DefaultSpringOrdinaryUserAccountRepositoryTest.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
at org.testng.TestNG.run(TestNG.java:1031)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
Caused by: javax.persistence.RollbackException: Exception [EclipseLink-45] (Eclipse Persistence Services - 2.6.2.v20151217-774c696): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Missing mapping for field [ordinary_user_account.id].
Descriptor: RelationalDescriptor(com.projects.simpleaccount.account.authorizationmanageableaccount.AuthorityScope --> [DatabaseTable(ordinary_user_account)])
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:159)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517)
... 39 more
Caused by: Exception [EclipseLink-45] (Eclipse Persistence Services - 2.6.2.v20151217-774c696): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Missing mapping for field [ordinary_user_account.id].
Descriptor: RelationalDescriptor(com.projects.simpleaccount.account.authorizationmanageableaccount.AuthorityScope --> [DatabaseTable(ordinary_user_account)])
at org.eclipse.persistence.exceptions.DescriptorException.missingMappingForField(DescriptorException.java:983)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.extractValueFromObjectForField(ObjectBuilder.java:3209)
at org.eclipse.persistence.mappings.AggregateCollectionMapping.getReferenceObjectKeys(AggregateCollectionMapping.java:1456)
at org.eclipse.persistence.mappings.AggregateCollectionMapping.getAndPrepareModifyQueryForInsert(AggregateCollectionMapping.java:2567)
at org.eclipse.persistence.mappings.AggregateCollectionMapping.preInsert(AggregateCollectionMapping.java:2512)
at org.eclipse.persistence.descriptors.DescriptorQueryManager.preInsert(DescriptorQueryManager.java:1093)
at org.eclipse.persistence.mappings.AggregateMapping.preInsertAttributeValue(AggregateMapping.java:861)
at org.eclipse.persistence.mappings.AggregateMapping.preInsert(AggregateMapping.java:831)
at org.eclipse.persistence.descriptors.DescriptorQueryManager.preInsert(DescriptorQueryManager.java:1093)
at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.insertObjectForWrite(DatabaseQueryMechanism.java:439)
at org.eclipse.persistence.queries.InsertObjectQuery.executeCommit(InsertObjectQuery.java:80)
at org.eclipse.persistence.queries.InsertObjectQuery.executeCommitWithChangeSet(InsertObjectQuery.java:90)
at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:301)
at org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:58)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:904)
at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:803)
at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:108)
at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:85)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1857)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1839)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1790)
at org.eclipse.persistence.internal.sessions.CommitManager.commitNewObjectsForClassWithChangeSet(CommitManager.java:227)
at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsForClassWithChangeSet(CommitManager.java:194)
at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:139)
at org.eclipse.persistence.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:4263)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1441)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1531)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java:278)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitAndResume(UnitOfWorkImpl.java:1169)
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:134)
... 40 more
ordinary_user_account.xml(ORM):
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm
http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd"
version="2.1">
<entity name="OrdinaryUserAccount" class="com.projects.identityaccess.domain.model.account.ordinaryuseraccount.OrdinaryUserAccount" access="FIELD" >
<table name="ordinary_user_account" />
<convert converter="com.projects.identityaccess.infrastructure.jpa.converters.OrdinaryUserUniqueAccountNameConverter" attribute-name="name"/>
<attributes>
<embedded-id name="id" >
<attribute-override name="numId">
<column name="id"/>
</attribute-override>
</embedded-id>
<basic name="isAccounNotLocked">
<column name="blocked" />
</basic>
<basic name="name">
<column name="account_name" length="50" />
</basic>
<one-to-one name="user" fetch="LAZY" target-entity="com.projects.identityaccess.domain.model.user.ordinaryuser.OrdinaryUser">
<join-column name="owner_id" referenced-column-name="id"/>
</one-to-one>
<embedded name="authorityScope" />
</attributes>
</entity>
<embeddable class="com.projects.identityaccess.domain.model.account.ordinaryuseraccount.OrdinaryUserAccountId" access="FIELD">
<attributes>
<basic name="numId">
<column name="id"/>
</basic>
</attributes>
</embeddable>
<embeddable class="com.projects.simpleaccount.account.authorizationmanageableaccount.AuthorityScope" access="FIELD">
<attributes>
<element-collection name="authorities" target-class="com.projects.identityaccess.domain.model.account.authorityscope.OrdinaryUserRole" access="FIELD">
<collection-table name="ordinary_user_account_authorities">
<join-column name="account_id" referenced-column-name="id"/>
</collection-table>
</element-collection>
</attributes>
</embeddable>
<embeddable class="com.projects.identityaccess.domain.model.account.authorityscope.OrdinaryUserRole" access="FIELD" >
<attributes>
<basic name="role">
<column name="role_name" />
</basic>
</attributes>
</embeddable>
<converter class="com.projects.identityaccess.infrastructure.jpa.converters.OrdinaryUserUniqueAccountNameConverter" />
</entity-mappings>
我非常确定问题与元素收集有关,因为我已尝试将<embedded name="authorityScope"/>
替换为<transient name="authorityScope" />
,问题完全消失。