我有一个类似于this question中描述的表关系,我尝试了他们说他们在那里修复它的方式。得到此could not initialize a collection
错误。我环顾四周并将其更改为拥有第三个实体和两个原始类,Set
与OneToMany
映射到该实体,而不是使用Map
和ManyToMany
映射。
如果我只是在我面前丢失了一些愚蠢的东西,这是我的桌子:
create table email_distribution_templates (
id number primary key,
from_address varchar2(50) not null,
subject varchar2(250) not null,
body varchar2(4000),
send_time date,
send_type varchar2(10),
email_type varchar2(50),
attachments_by varchar2(10),
attachment_info varchar2(50),
last_sent date,
CONSTRAINT unique_email_subject UNIQUE (subject)
);
create sequence distro_seq CACHE 50;
create table email_distribution_addressees (
id number primary key,
first_name varchar2(50),
last_name varchar2(50),
address varchar2(100) not null
);
create sequence addressee_seq CACHE 50;
create table addressees_for_distributions (
distro_id number not null references email_distribution_templates(id),
addressee_id number not null references email_distribution_addressees(id),
addressee_type varchar2(3) not null,
constraint adrs_fr_dist primary key(distro_id, addressee_id)
);
create sequence ad_fr_dst_seq CACHE 50;
以下是他们相应的实体:
@Entity
@Table(name = "email_distribution_templates")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@SequenceGenerator(sequenceName = "distro_seq", name = "distro_seq", allocationSize = 1)
@Configurable(autowire = Autowire.BY_TYPE)
public class EmailDistributionTemplate implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "distro_seq")
private long id;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "distro")
private Set<AddresseeForDistribution> addresseeForDistribution = Sets.newHashSet();
@NotNull
Email
private String fromAddress;
@NotNull
private String subject;
private String body;
private DateTime sendTime;
Enumerated(EnumType.STRING)
private SendTimeType sendType;
@Enumerated(EnumType.STRING)
private EmailType emailType;
@Enumerated(EnumType.STRING)
private AttachmentsBy attachmentsBy;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "email")
private Set<EmailSent> emailSentTimes = Sets.newHashSet();
private DateTime lastSent;
private String attachmentInfo;
@Transient
private List<String> attachments = new ArrayList<String>();
@Transient
private String tempBody;
//getters and setters
}
@Entity
@Table(name = "email_distribution_addressees")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@SequenceGenerator(sequenceName = "addressee_seq", name = "addressee_seq", allocationSize = 1)
@Configurable(autowire = Autowire.BY_TYPE)
public class EmailDistributionAddressee implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "addressee_seq")
private long id;
@OneToMany(mappedBy = "addressee")
private Set<AddresseeForDistribution> addresseeForDistribution = Sets.newHashSet();
@Email
@NotNull
private String address;
private String firstName;
private String lastName;
//getters and setters
}
这是在Set
类中形成EmailDistributionTemplate
时出现问题的实体:
@Entity
@Table(name = "addressees_for_distributions")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Configurable(autowire = Autowire.BY_TYPE)
public class AddresseeForDistribution implements Serializable {
private static final long serialVersionUID = 1L;
// @EmbeddedId
// private Id id;
@Id
private long id;
@ManyToOne(optional = false)
@JoinColumn(name = "distro_id", referencedColumnName = "id", insertable = false, updatable = false)
private EmailDistributionTemplate distro;
@ManyToOne(optional = false)
@JoinColumn(name = "addressee_id", referencedColumnName = "id", insertable = false, updatable = false)
private EmailDistributionAddressee addressee;
@Column(name = "addressee_type")
private AddresseeType addresseeType;
//getters and setters
}
正如您所看到的,有一些与嵌入式ID相关的注释掉的位,我得到了同样的错误,所以我想我会尝试没有。
这是堆栈跟踪:
Hibernate: select addresseef0_.distro_id as distro_i4_12_1_, addresseef0_.id as id1_0_1_, addresseef0_.id as id1_0_0_, addresseef0_.addressee_id as addresse3_0_0_, addresseef0_.addressee_type as addresse2_0_0_, addresseef0_.distro_id as distro_i4_0_0_ from addressees_for_distributions addresseef0_ where addresseef0_.distro_id=?
13018 [main] WARN o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 17059, SQLState: 99999
13018 [main] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - Fail to convert to internal representation
13028 [main] WARN o.h.e.loading.internal.LoadContexts - HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@37e79b10<rs=org.apache.commons.dbcp.DelegatingResultSet@144e1c6e>
13028 [main] WARN o.h.e.l.i.CollectionLoadContext - HHH000160: On CollectionLoadContext#cleanup, localLoadingCollectionKeys contained [1] entries
13038 [main] ERROR o.s.batch.core.step.AbstractStep - Encountered an error executing step processEmailStep in job sendEmailJob
org.springframework.batch.core.step.skip.NonSkippableReadException: Non-skippable exception during read
at org.springframework.batch.core.step.item.FaultTolerantChunkProvider.read(FaultTolerantChunkProvider.java:104) ~[spring-batch-core-2.2.7.RELEASE.jar:na]
at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:114) ~[spring-batch-core-2.2.7.RELEASE.jar:na]
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:368) ~[spring-batch-infrastructure-2.2.7.RELEASE.jar:na]
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-2.2.7.RELEASE.jar:na]
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144) ~[spring-batch-infrastructure-2.2.7.RELEASE.jar:na]
at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:108) ~[spring-batch-core-2.2.7.RELEASE.jar:na]
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:69) ~[spring-batch-core-2.2.7.RELEASE.jar:na]
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:395) ~[spring-batch-core-2.2.7.RELEASE.jar:na]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133) ~[spring-tx-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:267) ~[spring-batch-core-2.2.7.RELEASE.jar:na]
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:77) ~[spring-batch-core-2.2.7.RELEASE.jar:na]
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:368) ~[spring-batch-infrastructure-2.2.7.RELEASE.jar:na]
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-2.2.7.RELEASE.jar:na]
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144) ~[spring-batch-infrastructure-2.2.7.RELEASE.jar:na]
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:253) ~[spring-batch-core-2.2.7.RELEASE.jar:na]
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195) ~[spring-batch-core-2.2.7.RELEASE.jar:na]
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:141) [spring-batch-core-2.2.7.RELEASE.jar:na]
at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:380) [spring-batch-core-2.2.7.RELEASE.jar:na]
at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:124) [spring-batch-core-2.2.7.RELEASE.jar:na]
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:301) [spring-batch-core-2.2.7.RELEASE.jar:na]
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:134) [spring-batch-core-2.2.7.RELEASE.jar:na]
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) [spring-core-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:127) [spring-batch-core-2.2.7.RELEASE.jar:na]
at com.stuff.my.app.email.SendEmailJobITest.sendEmail(SendEmailJobITest.java:58) [test-classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.6.0_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.6.0_45]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.6.0_45]
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) [junit-4.11.jar:na]
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.11.jar:na]
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) [junit-4.11.jar:na]
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) [junit-4.11.jar:na]
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) [spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83) [spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) [spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233) [spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87) [spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) [junit-4.11.jar:na]
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) [junit-4.11.jar:na]
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) [junit-4.11.jar:na]
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) [junit-4.11.jar:na]
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) [junit-4.11.jar:na]
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) [spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) [spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.junit.runners.ParentRunner.run(ParentRunner.java:309) [junit-4.11.jar:na]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176) [spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) [.cp/:na]
Caused by: org.springframework.orm.jpa.JpaSystemException: could not initialize a collection: [com.stuff.my.app.email.EmailDistributionTemplate.addresseeForDistribution#-1]; nested exception is org.hibernate.exception.GenericJDBCException: could not initialize a collection: [com.stuff.my.app.email.EmailDistributionTemplate.addresseeForDistribution#-1]
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:244) ~[spring-orm-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:155) ~[spring-orm-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:417) ~[spring-orm-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59) ~[spring-tx-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213) ~[spring-tx-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147) ~[spring-tx-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.data.jpa.repository.support.LockModeRepositoryPostProcessor$LockModePopulatingMethodIntercceptor.invoke(LockModeRepositoryPostProcessor.java:92) ~[spring-data-jpa-1.3.4.RELEASE.jar:na]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at com.sun.proxy.$Proxy113.findNotSentBySendTime(Unknown Source) ~[na:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.6.0_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.6.0_45]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.6.0_45]
at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:269) ~[spring-core-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.batch.item.data.RepositoryItemReader.doInvoke(RepositoryItemReader.java:243) ~[spring-batch-infrastructure-2.2.7.RELEASE.jar:na]
at org.springframework.batch.item.data.RepositoryItemReader.doPageRead(RepositoryItemReader.java:208) ~[spring-batch-infrastructure-2.2.7.RELEASE.jar:na]
at org.springframework.batch.item.data.RepositoryItemReader.doRead(RepositoryItemReader.java:153) ~[spring-batch-infrastructure-2.2.7.RELEASE.jar:na]
at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:83) ~[spring-batch-infrastructure-2.2.7.RELEASE.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.6.0_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.6.0_45]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.6.0_45]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at com.sun.proxy.$Proxy111.read(Unknown Source) ~[na:na]
at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:91) ~[spring-batch-core-2.2.7.RELEASE.jar:na]
at org.springframework.batch.core.step.item.FaultTolerantChunkProvider.read(FaultTolerantChunkProvider.java:87) ~[spring-batch-core-2.2.7.RELEASE.jar:na]
... 51 common frames omitted
Caused by: org.hibernate.exception.GenericJDBCException: could not initialize a collection: [com.stuff.my.app.email.EmailDistributionTemplate.addresseeForDistribution#-1]
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.loader.Loader.loadCollection(Loader.java:2267) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.loader.collection.LegacyBatchingCollectionInitializerBuilder$LegacyBatchingCollectionInitializer.initialize(LegacyBatchingCollectionInitializerBuilder.java:100) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:674) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:86) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1774) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.collection.internal.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:681) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.engine.internal.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:1030) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:353) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2548) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2534) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2364) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.loader.Loader.list(Loader.java:2359) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:495) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:357) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1194) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:268) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.springframework.data.jpa.repository.query.JpaQueryExecution$PagedExecution.doExecute(JpaQueryExecution.java:108) ~[spring-data-jpa-1.3.4.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:55) ~[spring-data-jpa-1.3.4.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:95) ~[spring-data-jpa-1.3.4.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:85) ~[spring-data-jpa-1.3.4.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:312) ~[spring-data-commons-1.5.2.RELEASE.jar:na]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98) ~[spring-tx-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262) ~[spring-tx-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95) ~[spring-tx-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.0.4.RELEASE.jar:4.0.4.RELEASE]
... 81 common frames omitted
Caused by: java.sql.SQLException: Fail to convert to internal representation
at oracle.jdbc.driver.CharCommonAccessor.getInt(CharCommonAccessor.java:147) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CVarcharAccessor.getInt(T4CVarcharAccessor.java:828) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
at oracle.jdbc.driver.OracleResultSetImpl.getInt(OracleResultSetImpl.java:942) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
at oracle.jdbc.driver.OracleResultSet.getInt(OracleResultSet.java:434) ~[ojdbc6-11.2.0.3.jar:11.2.0.3.0]
at org.apache.commons.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:275) ~[commons-dbcp-1.4.jar:1.4]
at org.apache.commons.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:275) ~[commons-dbcp-1.4.jar:1.4]
at org.hibernate.type.EnumType$OrdinalEnumValueMapper.getValue(EnumType.java:372) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.type.EnumType.nullSafeGet(EnumType.java:107) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:127) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:106) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2924) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1695) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1627) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.loader.Loader.getRow(Loader.java:1509) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:719) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.loader.Loader.processResultSet(Loader.java:949) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.loader.Loader.doQuery(Loader.java:917) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:348) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:318) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.loader.Loader.loadCollection(Loader.java:2260) ~[hibernate-core-4.2.8.Final.jar:4.2.8.Final]
... 109 common frames omitted
我认为Hibernate正在成为我存在的祸根。任何想法或帮助将不胜感激。我已经谷歌搜索和修补,并试图解决这个错误几天了。我觉得这可能是我忽略的愚蠢行为。
答案 0 :(得分:0)
我通过让Hibernate
为我创建表并将它们与我的脚本和代码进行比较来解决问题。 是一些愚蠢的东西,就在我面前。我错过了enum
AddresseesForDistribution
的注释
我将以下代码放在main
方法中让Hibernate为我生成表创建并将其输出到日志/控制台:
Configuration config = new Configuration();
config.addAnnotatedClass(AddresseeForDistribution.class);
config.addAnnotatedClass(EmailDistributionAddressee.class);
config.addAnnotatedClass(EmailDistributionTemplate.class);
config.addAnnotatedClass(EmailSent.class);
config.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
new SchemaExport(config).create(true,false); //the true tells it to output to the log/console, the false tells it to not actually touch the db
感谢UweAllner指点我的方向!
答案 1 :(得分:0)
希望您还在hibernate.cfg.xml文件中声明了带注释类的映射。