你好我有这个错误信息,我真的不知道该怎么做。
“通过未标记为级联PERSIST的关系找到了一个新对象”
我知道实体关系有问题,但我尝试了很多东西而且没有用。
这是我的两个豆子:
@Entity
public class Emoji implements Serializable {
private static long serialVersionUID = 1L;
public static long getSerialVersionUID() {
return serialVersionUID;
}
public static void setSerialVersionUID(long aSerialVersionUID) {
serialVersionUID = aSerialVersionUID;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne
private Utilisateur createur;
private String titre;
private List<Message> conversations;...
...
@Entity
public class Message implements Serializable {
private static long serialVersionUID = 1L;
public static long getSerialVersionUID() {
return serialVersionUID;
}
public static void setSerialVersionUID(long aSerialVersionUID) {
serialVersionUID = aSerialVersionUID;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String message;
@ManyToOne
private Utilisateur auteur;
public Message() {
} ...
答案 0 :(得分:1)
将import org.junit.Before;
import org.junit.Test;
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.junit.Assert.fail;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsNull.notNullValue;
public class SingletonTest {
@Before
public void resetSingleton() throws NoSuchFieldException, IllegalAccessException {
Field instance = Singleton.class.getDeclaredField("singleton");
instance.setAccessible(true);
instance.set(null, null);
}
@Test
public void singletonCanFindFile() throws Exception {
final Path path = Paths.get("maybeIExist.txt");
Files.createFile(path);
final Singleton instance = Singleton.getInstance();
assertThat(instance, notNullValue());
Files.deleteIfExists(path);
}
@Test(expected = ExceptionInInitializerError.class)
public void singletonCannotFindFile() throws Exception {
final Singleton instance = Singleton.getInstance();
fail("no exception thrown!");
}
}
注释添加到@OneToMany
字段。
conversations