I have two tables (command and commandLine), i want to write in both when i insert a new command Here is my Command Object, I use a OneToMany to map with the object CommandLine
@Entity
@Table(name = "t_commands")
public class Command {
@Id @Getter
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idCommand;
@Getter @Setter
@ManyToOne(targetEntity = User.class)
@JoinColumn(name = "idUser", nullable = false)
private User user;
@Getter @Setter
@Column(name = "commandDate")
private String date;
@Getter @Setter
@OneToMany(targetEntity = CommandLine.class, mappedBy = "idCommand")
private List<CommandLine> lines = new ArrayList<>();
public Command(User user, String date) {
this.user = user;
this.date = date;
}
public Command() {
}
and my CommandLine object, I use ManyToOne to map with the object Command
@Entity
@Table(name = "t_commandlines")
public class CommandLine {
@Id @Getter
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idCommandLine;
@Getter
@ManyToOne(targetEntity = Command.class, cascade = CascadeType.ALL)
@JoinColumn(name = "idCommand", nullable = false)
private Command idCommand;
@Getter @Setter
@ManyToOne(targetEntity = Article.class)
@JoinColumn(name = "idArticle", nullable = false)
private Article article;
@Getter @Setter
private int quantity;
public CommandLine(Article article, int quantity) {
this.article = article;
this.quantity = quantity;
}
and my CommandDAO
public class CommandDAO implements IDao<Command> {
@Override
public boolean create(Command object) {
connect().persist(object);
return true;
}
}
I use interface
public interface IDao<T> {
default EntityManager connect() {
EntityManagerFactory entityManagerFactory;
EntityManager entityManager;
entityManagerFactory = Persistence.createEntityManagerFactory("webstore");
entityManager = entityManagerFactory.createEntityManager();
return entityManager;
}
default T read(Long id){return null;}
default List<T> getAll() {return null;}
default boolean create(T object) {return false;}
default boolean update(T object) {return false;}
default boolean delete(T object) {return false;}
default Long getCount() {return 1L;}
}
I have no error, but nothing is writing in my db, I have no problem to retrieve data from the db with this structure, but impossible to write