jpa spring-test冲洗错误

时间:2013-02-25 11:32:45

标签: java spring jpa junit spring-test

我的表Product在我的数据库中有这样的字段:

@Transient
private Map<Locale, String> description = new HashMap<>();

description在课程ProductLocalization中定义。

我将columnDefinition = "LONGTEXT"添加到

之后
@Column(name = Product.COLUMN_DESCRIPTION, columnDefinition = "LONGTEXT")
private String description;

在那个课程中我可以根据需要设置超过255个标记的描述,但我的两个测试在productDao.saveAndFlush(product) product.setDescription(descriptions)之前的行中开始失败,重要的是当我在应用程序中执行该操作,而不是在测试中一切正常,只有测试导致问题

saveAndFlush()是我从包org.springframework.data.jpa.repository

获得的方法

两个测试中的错误相同:

javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: PRODUCT_LOCALIZED
Error Code: -5501
Call: INSERT INTO product_localized (description, entity_id, language) VALUES (?, ?, ?)
    bind => [angielski, 3, en]
Query: InsertObjectQuery(ProductLocalization{description=angielski})
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:804)

这是测试代码:

 @Test
public void testMultilingualCreate() {
    // Given
    String polish = "polski", english = "angielski";
    Product product = new Product();
    product.setName("Product name");
    Map<Locale, String> descriptions = new HashMap<>(); 
    descriptions.put(Locale.ENGLISH, english);
    descriptions.put(Messages.POLISH, polish);

    // When
    product.setDescription(descriptions);
    Product p = productDao.saveAndFlush(product);
    product = productDao.findOne(p.getId());

    // Then
    assertEquals(polish, product.getDescription(Messages.POLISH));
    assertEquals(english, product.getDescription(Locale.ENGLISH));
}

@Test
public void testMultilingualUpdate() {
    // Given
    String polish = "polski", english = "angielski", english2 = "another english description";
    Product product = new Product();
    product.setName("Product name");
    Map<Locale, String> descriptions = new HashMap<>(); 
    descriptions.put(Locale.ENGLISH, english);
    descriptions.put(Messages.POLISH, polish);

    // When
    product.setDescription(descriptions);
    product = productDao.saveAndFlush(product);
    assertEquals(english, product.getDescription(Locale.ENGLISH));
    descriptions.put(Locale.ENGLISH, english2);
    product.setDescription(descriptions);
    product = productDao.saveAndFlush(product);

    // Then
    assertEquals(polish, product.getDescription(Messages.POLISH));
    assertEquals(english2, product.getDescription(Locale.ENGLISH));
}

这里有什么问题我该如何解决?

0 个答案:

没有答案