0

私はMarketエンティティを持っています

@Entity
public class Market extends MutableEntity {

    @Column(nullable = false)
    private String name;
    @Column
    private String description;
    @Embedded
    private Version marketVersion; // snipped

およびVersionエンティティとして

@Embeddable
public class Version {
    private double versionNumber;
    private VersionType versionType;
    private DateTime publishedOn;
    private DateTime retiredOn;
    private double parentVersionNumber; //snipped

以下をテストしようとすると、失敗します

   @Test
    public void testCloneMarket() {
        final String name = "testCloneMarket";
        final String description = "testCloneMarket";
        final Market existingMarket = new MarketManager(crudService).addMarket(name, description);

        // publish market
        existingMarket.getMarketVersion().setPublishedOn(new DateTime()); // fails here


        assertNotNull(existingMarket);
    }

エラーは次のように表示されます

testCloneMarket(com.myorg.project.versioning.business.MarketManagerTest)  Time elapsed: 4.11 sec  <<< ERROR!
javax.persistence.RollbackException: Error while committing the transaction
    at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:90)
    at com.myorg.toolkit.commons.persistence_testing.rules.JpaRule.commitOrRollbackTransaction(JpaRule.java:220)
    at com.myorg.toolkit.commons.persistence_testing.rules.JpaRule.changeTransaction(JpaRule.java:155)
    at com.myorg.project.versioning.business.MarketManagerTest.testCloneMarket(MarketManagerTest.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.DataException: A truncation error was encountered trying to shrink VARCHAR () FOR BIT DATA '(Binary data value not displayed)' to length 255.

derbyインメモリテストに使用しています。なぜこの問題が発生し、解決策は何ですか?

ありがとうございました

4

2 に答える 2

0

切り捨てエラーが発生している列は明確ではありません。

例外チェーンを完全に巻き戻すことで、例外チェーンからより多くの情報を取得することができます:このアドバイス を参照してください

または、derby.log ファイルが見つかり、アプリケーションを -Dderby.language.logStatementText=true で実行できる場合は、詳細を確認できるはずです。

Derby データ型VARCHAR FOR BIT DATAは、32,672 バイトまでの指定長をサポートします。デフォルトの長さはありません。そのため、256 バイトの長さは、アプリケーションまたは永続化レイヤーの実装に使用しているフレームワークの 1 つで設定したものでなければなりません。

永続化レイヤーがテーブル スキーマを生成している場所がわかれば、それをオーバーライドして、VARCHAR FOR BIT DATA 列に別の長さを選択できるはずです。

于 2013-02-12T14:58:25.920 に答える
0

のソースが見つかりませんsetPublishedOn

お試しのみ!!

DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
existingMarket.getMarketVersion().setPublishedOn(dateFormat.format(date));
于 2013-02-11T20:13:59.060 に答える