I basically have a Class A and a Class B where ClassA has many of ClassB, i use a OneToMany annotation to get a List of all the ClassB Objects that belong to a ClassA Object, now i want to convert the information in ClassA to a ClassA DTO but in the DTO i only want a list of the ids of the ClassB Objects and not the Objects. Im using the Spring Framework and the ModelMapper, the data of the objects can be accessed via rest api in Json format.
ClassA:
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.ArrayList;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "ClassA")
public class ClassA implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(
mappedBy = "myClassA",
cascade = CascadeType.ALL,
orphanRemoval = true
)
private java.util.List<Domain> domains = new ArrayList<>();
}
ClassB:
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDate;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "ClassB")
public class ClassB implements Serializable {
private static final long serialVersionUID = 1L;
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
private Long id;
@Column(name="projekt_id")
private Long projectId;
@ManyToOne
@JsonIgnore
@JoinColumn(name = "projekt_id", insertable = false, updatable = false)
private ClassA myClassA;
}