Hibernate annotion multi-to-Multi-link example

Source: Internet
Author: User
Tags sql error

Objects are many-to-many relationships,


The error entity code is as follows:


Java code:
 
 
  1. @ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
  2. @JoinTable(name = "product_packagetype:packageTypes:products")
  3. private java.util.Listimplambition.forxxx.model.PackageType> packageTypes;
  4. /**
  5. * @generated
  6. */
  7. @ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
  8. @JoinTable(name = "product_productcolor:productColors:products")
  9. private java.util.Listimplambition.forxxx.model.ProductColor> productColors;
  10. /**
  11. * @generated
  12. */
  13. @ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
  14. @JoinTable(name = "product_attach:attachs:products")
  15. private java.util.Listimplambition.forxxx.model.Attach> attachs;

The Code itself cannot run normally, and the error cannot simultaneously fetch multiple bags is reported.
After fetchtype. Lazy is changed, the following error occurs: Warn [main] 16:46:18, 655-SQL error: 1064, sqlstate: 42000
Error
[Main] 16:46:18, 655-you have an error in your SQL syntax;
Check the manual that corresponds to your MySQL Server version for
Right syntax to use near ': packagetypes: Products packagetyp0 _ left
Outer Join packagetype packagetyp1 _ on 'at line 1

The last modification can only be:
Product entity


Java code:
 
 
  1. /**
  2. * @generated
  3. */
  4. @ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
  5. //@JoinTable(name = "product_packagetype:packageTypes:products")
  6. @JoinTable(name = "product_packagetype", joinColumns = { @JoinColumn(name = "packageTypes") }, inverseJoinColumns = { @JoinColumn(name = "products") })
  7. private java.util.Listimplambition.forxxx.model.PackageType> packageTypes;
  8. /**
  9. * @generated
  10. */
  11. @ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
  12. //@JoinTable(name = "product_productcolor:productColors:products")
  13. @JoinTable(name = "product_productcolor", joinColumns = { @JoinColumn(name = "productColors") }, inverseJoinColumns = { @JoinColumn(name = "products") })
  14. private java.util.Listimplambition.forxxx.model.ProductColor> productColors;
  15. /**
  16. * @generated
  17. */
  18. @ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
  19. //@JoinTable(name = "product_attach:attachs:products")
  20. @JoinTable(name = "product_attach", joinColumns = { @JoinColumn(name = "attachs") }, inverseJoinColumns = { @JoinColumn(name = "products") })
  21. private java.util.Listimplambition.forxxx.model.Attach> attachs;

Only one example of other associated entities is listed. The Code is as follows (the code generated by studio is commented out)


Java code:
 
 
  1. /**
  2. * @generated
  3. */
  4. //@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
  5. @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy="attachs")
  6. private java.util.Listimplambition.forxxx.model.Product> products;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.