我的数据库中有类似字段的表Product
:
@Transient
private Map<Locale, String> description = new HashMap<>();
description
在类中定义ProductLocalization
。
在我添加columnDefinition = "LONGTEXT"
到
@Column(name = Product.COLUMN_DESCRIPTION, columnDefinition = "LONGTEXT")
private String description;
在该课程中,我可以根据需要设置超过 255 分的描述,但是我的 2 个测试在productDao.saveAndFlush(product)
at之前开始失败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));
}
这里有什么问题我该如何解决?