Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Set<;上使用@ElementCollection将数据重新插入表中;字符串>;_Java_Hibernate_Spring Data Jpa_Jpa 2.0 - Fatal编程技术网

Java 在Set<;上使用@ElementCollection将数据重新插入表中;字符串>;

Java 在Set<;上使用@ElementCollection将数据重新插入表中;字符串>;,java,hibernate,spring-data-jpa,jpa-2.0,Java,Hibernate,Spring Data Jpa,Jpa 2.0,我在我的项目中使用JPA2.0,并且在Pojo类中的一个属性上使用了@ElementCollection 以下是我的java实体类: @Entity @Embeddable @Table(name = "test") public class Test { @Id @GeneratedValue(generator = "seq_test") @SequenceGenerator(name = "seq_test", sequenceName = "seq_test") @Column(nam

我在我的项目中使用JPA2.0,并且在Pojo类中的一个属性上使用了@ElementCollection

以下是我的java实体类:

@Entity
@Embeddable
@Table(name = "test")
public class Test {

@Id
@GeneratedValue(generator = "seq_test")
@SequenceGenerator(name = "seq_test", sequenceName = "seq_test")
@Column(name = "id")
private Long id;

@ElementCollection(fetch = FetchType.LAZY, targetClass = String.class)
@CollectionTable(name = "denied_set")
@OrderColumn
private Set<String> deniedSet;

@ElementCollection(fetch = FetchType.LAZY, targetClass = String.class)
@CollectionTable(name = "masked_set")
@OrderColumn
private Set<String> maskedSet;

@ElementCollection(fetch = FetchType.LAZY, targetClass = String.class)
@CollectionTable(name = "user_groups")
@OrderColumn
private Set<String> userGroups;

public Long getId() {
  return id;
}

public void setId(Long id) {
  this.id = id;
}

public Set<String> getDeniedSet() {
  return deniedSet;
}

public void setDeniedSet(Set<String> deniedSet) {
  this.deniedSet = deniedSet;
}

public Set<String> getMaskedSet() {
  return maskedSet;
}

public void setMaskedSet(Set<String> maskedSet) {
  this.maskedSet = maskedSet;
}

public Set<String> getUserGroups() {
  return userGroups;
}

public void setUserGroups(Set<String> userGroups) {
  this.userGroups = userGroups;
}

}
@实体
@可嵌入
@表(name=“test”)
公开课考试{
@身份证
@GeneratedValue(generator=“seq_测试”)
@SequenceGenerator(name=“seq_测试”,sequenceName=“seq_测试”)
@列(name=“id”)
私人长id;
@ElementCollection(fetch=FetchType.LAZY,targetClass=String.class)
@CollectionTable(name=“拒绝设置”)
@订单列
私有集拒绝集;
@ElementCollection(fetch=FetchType.LAZY,targetClass=String.class)
@CollectionTable(name=“masked\u set”)
@订单列
私有集掩码集;
@ElementCollection(fetch=FetchType.LAZY,targetClass=String.class)
@CollectionTable(name=“用户组”)
@订单列
私有用户组;
公共长getId(){
返回id;
}
公共无效集合id(长id){
this.id=id;
}
公共集getDeniedSet(){
返回拒绝集;
}
公共无效集合deniedSet(集合deniedSet){
this.deniedSet=deniedSet;
}
公共集getMaskedSet(){
返回掩码集;
}
公共无效集合maskedSet(集合maskedSet){
this.maskedSet=maskedSet;
}
公共集getUserGroups(){
返回用户组;
}
public void setUserGroups(Set userGroups){
this.userGroups=用户组;
}
}
我正在使用SpringDataJPA存储库与数据库进行交互。数据已正确插入到数据库表中。当我从表中删除一些数据时,我可以在日志中看到,删除查询也会在子表上执行,之后相同的数据会重新插入到表中

如果我在代码中遗漏了什么,有人能帮我理解吗


提前感谢。

一些问题可能会对您有所帮助:

  • 您需要@Embedded公共类测试吗?如果您没有在中使用它 然后另一个拥有实体将其删除

  • 指定应将哪个列用作 @元素集合。使用类似以下内容: @CollectionTable(name=“denied\u set”, JoinColumns=@JoinColumn(name=“COLUMN\u name”))或在 deniad_套件可嵌入

  • 在ElementCollection上,默认情况下Fetch类型是惰性的,您真的需要targetClass吗
  • 否则在我看来它是正确的