Java @暂时无法在同一字段上使用@ElementCollection
我有这样的课Java @暂时无法在同一字段上使用@ElementCollection,java,mysql,jpa,spring-boot,spring-data,Java,Mysql,Jpa,Spring Boot,Spring Data,我有这样的课 { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; @ElementCollection @Transient @JsonProperty("custom_fields") private Map<String, String> customFields; private String descriptio
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@ElementCollection
@Transient
@JsonProperty("custom_fields")
private Map<String, String> customFields;
private String description;
}
{
@身份证
@GeneratedValue(策略=GenerationType.IDENTITY)
私人长id;
@元素集合
@短暂的
@JsonProperty(“自定义字段”)
私有地图字段;
私有字符串描述;
}
但是,我不希望“customFields”字段存储在数据库中。所以我使用了@Transient注释。但它正在创建新表和外键。“customFields”的值存储在该表中。我想这是因为@ElementCollection注释。如果我删除@ElementCollection,我将得到以下异常:无法确定表中java.util.Map的类型。然而,如果字段不是集合,@Transient可以完美地工作
我怎样才能做到这一点?我想在类中使用该字段,但不想将其存储在数据库中。希望此帮助()我已经尝试过了。但是,它不起作用,因为字段是集合类型。