简体   繁体   中英

Add data to abstract table Java spring

I have two entities generate by hibernate (in postgres)

here is my MCD (many to many - User bottle) : All work fine, but my abstract table is not completed.

Screen from my table User_Bottle :

在此处输入图片说明

i would like to add this data to my table, but i don't know how to do, here is my service (i'm beginner in spring):

    public void addBottleToUser(UserBottleDTO userBottleDto) {

    //Variable that i would like to add into my request
    String userEmail;
    Long bottleIdl;
    String scorel;
    String opinion;
    String with;
    String place;
    String date;

    User userDb = this.userDao.findByEmail(userBottleDto.getUserEmail());
    Bottle bottleDb = this.bottleDao.findById(userBottleDto.getBottleId());
    Set<Bottle> bottles = new HashSet<Bottle>();
    bottles = userDb.getBottles();
    bottles.add(bottleDb);
    userDb.setBottles(bottles);

    this.userDao.save(userDb);
}

user class (entity): https://pastebin.com/KAuyvBAJ

bottle class (entity): https://pastebin.com/NmrqpVEQ

i can print my DAO, DTO if you want, or something else.

If relation doesn't be annotated with @ManyToMany; you need to save your abstract table record same as bottle or user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM