我一直在从spring(2.5.5到4.0.2.RELEASE)和Hibernate(3.2.6到3.6.9)迁移我的应用程序。从Spring ORM JPA迁移我遇到了这个问题只是想让自己正确的是我的方式是对的,或者版本是所有这个问题的问题。
多个持续加载问题
Error creating bean with name 'something' defined in class path resource [spring/test-persistenceContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Conflicting persistence unit definitions for name
我通过
解决了这个问题然后它在那里顺利。但它给我构建实体时出错。
@Id
,其中在实体类中使用@EmbededId
和在密钥/ Id类中定义@ Id'通常使用getId()来获取相应的id。我从ID / Entity类中删除了所有@Id。@ManyToOne()
关系joincolumns
无法识别我删除了@joincolumns
annot以解决问题。现在我完全陷入了以下错误
Error creating bean with name 'something' defined in class path resource [spring/test-persistenceContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Foreign key (column names[1,2,3,4]) must have same number of columns as the referenced primary key (column names [1,2,4]).
不知道我已经修好了一个,但它继续出现像这个问题。 如果您需要移动堆栈跟踪详细信息,请告诉我。
public class AccountEntityKey extends AbstractEntityKey {
private String accountId;
}
@MappedSuperclass
@XmlAccessorType(XmlAccessType.PROPERTY)
public abstract class AbstractEntityKey implements EntityKey {
private String status;
}
public class Account extends AbstractAccount {
@Transient
private String accountId;
@Transient
private String status;
@Override
@EmbeddedId
@AttributeOverrides( {
@AttributeOverride(name = "accountId", column = @Column(name = "ACCT_ID", unique = false, nullable = false, insertable = true, updatable = false, length = 32)),
@AttributeOverride(name = "status", column = @Column(name = "ACCT_STA_TYP", unique = false, nullable = false, insertable = true, updatable = false, length = 10)) })
public AccountEntityKey getId() {
return (id != null) ? (AccountEntityKey) super.getId() : new AccountEntityKey(accountId,
status);}
}
public class AccountParty {
/**
* @return the account
* (cascade = {}, fetch = FetchType.LAZY)
* @JoinColumns( {
@JoinColumn(name = "ACCT_ID", unique = false, nullable = false, insertable = false, updatable = false),
@JoinColumn(name = "ACCT_STA_TYP", unique = false, nullable = false, insertable = false, updatable = false) })
*/
@ManyToOne
public Account getAccount() {
return account;
}
}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring/test-persistenceContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Foreign key (FKEC0DF9EF331D3E16:CLIENT_ACCOUNT_SERVICE [ACCT_ID,ACCT_PTY_STA_TYP,ACCT_ROLE_TYP,ACCT_STA_TYP,PTY_ID,PTY_ROLE_TYP,PTY_STA_TYP])) must have same number of columns as the referenced primary key (ACCOUNT_PARTY [ACCT_ID,ACCT_PTY_STA_TYP,ACCT_ROLE_TYP,PTY_ID,PTY_ROLE_TYP,PTY_STA_TYP])
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:973)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:750)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.test.AbstractSingleSpringContextTests.createApplicationContext(AbstractSingleSpringContextTests.java:216)
at org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:192)
at org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:172)
at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:133)
at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:101)
at junit.framework.TestCase.runBare(TestCase.java:125)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:79)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.hibernate.MappingException: Foreign key (FKEC0DF9EF331D3E16:CLIENT_ACCOUNT_SERVICE [ACCT_ID,ACCT_PTY_STA_TYP,ACCT_ROLE_TYP,ACCT_STA_TYP,PTY_ID,PTY_ROLE_TYP,PTY_STA_TYP])) must have same number of columns as the referenced primary key (ACCOUNT_PARTY [ACCT_ID,ACCT_PTY_STA_TYP,ACCT_ROLE_TYP,PTY_ID,PTY_ROLE_TYP,PTY_STA_TYP])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:112)
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:95)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1835)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1756)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1423)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1519)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1100)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:689)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:336)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
... 26 more