试图将VARCHAR()FOR BIT DATA'(二进制数据值未显示)'缩小到255

时间:2013-02-11 15:08:15

标签: java hibernate java-ee jpa derby

我有一个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进行内存中测试。 为什么会发生这种情况?它的解决方案是什么?

谢谢

2 个答案:

答案 0 :(得分:0)

我找不到setPublishedOn的来源。

只有尝试!!

DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
existingMarket.getMarketVersion().setPublishedOn(dateFormat.format(date));

答案 1 :(得分:0)

目前还不清楚哪个列遇到截断错误。

您可以尝试通过完全展开来从异常链中获取更多信息:see this advice

或者如果您可以找到您的derby.log文件,并且可以使用-Dderby.language.logStatementText = true运行您的应用程序,您应该能够看到更多详细信息。

Derby数据类型VARCHAR FOR BIT DATA支持最多32,672字节的指定长度。没有默认长度,因此256字节长度必须是您在应用程序或用于实现持久层的框架之一中设置的内容。

如果你能弄清楚持久层在哪里生成表模式,你应该能够覆盖它并为VARCHAR FOR BIT DATA列选择不同的长度。