JAVA 代码:
@ManyToMany
(cascade = CascadeType.
PERSIST, fetch = FetchType.
EAGER
)
@JoinTable
(name =
"product_packagetype:packageTypes:products"
)
private java.
util.
List
implambition.
forxxx.
model.
PackageType> packageTypes;
/**
* @generated
*/
@ManyToMany
(cascade = CascadeType.
PERSIST, fetch = FetchType.
EAGER
)
@JoinTable
(name =
"product_productcolor:productColors:products"
)
private java.
util.
List
implambition.
forxxx.
model.
ProductColor> productColors;
/**
* @generated
*/
@ManyToMany
(cascade = CascadeType.
PERSIST, fetch = FetchType.
EAGER
)
@JoinTable
(name =
"product_attach:attachs:products"
)
private java.
util.
List
implambition.
forxxx.
model.
Attach> attachs;
这样的代码本身不能正常运行,报错 cannot simultaneously fetch multiple bags。
改成FetchType.LAZY后,报错 WARN [main] 2009-05-10 16:46:18,655 - SQL Error: 1064, SQLState: 42000
ERROR [main] 2009-05-10 16:46:18,655 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':packageTypes:products packagetyp0_ left outer join PackageType packagetyp1_ on ' at line 1
最后只能修改为:
Product实体
JAVA 代码:
/**
* @generated
*/
@ManyToMany
(cascade = CascadeType.
PERSIST, fetch = FetchType.
LAZY
)
//@JoinTable(name = "product_packagetype:packageTypes:products")
@JoinTable
(name =
"product_packagetype", joinColumns =
{ @JoinColumn
(name =
"packageTypes"
)
}, inverseJoinColumns =
{ @JoinColumn
(name =
"products"
)
}
)
private java.
util.
List
implambition.
forxxx.
model.
PackageType> packageTypes;
/**
* @generated
*/
@ManyToMany
(cascade = CascadeType.
PERSIST, fetch = FetchType.
LAZY
)
//@JoinTable(name = "product_productcolor:productColors:products")
@JoinTable
(name =
"product_productcolor", joinColumns =
{ @JoinColumn
(name =
"productColors"
)
}, inverseJoinColumns =
{ @JoinColumn
(name =
"products"
)
}
)
private java.
util.
List
implambition.
forxxx.
model.
ProductColor> productColors;
/**
* @generated
*/
@ManyToMany
(cascade = CascadeType.
PERSIST, fetch = FetchType.
LAZY
)
//@JoinTable(name = "product_attach:attachs:products")
@JoinTable
(name =
"product_attach", joinColumns =
{ @JoinColumn
(name =
"attachs"
)
}, inverseJoinColumns =
{ @JoinColumn
(name =
"products"
)
}
)
private java.
util.
List
implambition.
forxxx.
model.
Attach> attachs;
其他关联实体只列出一个示例,代码如下(注释掉的为studio生成的代码)
JAVA 代码:
/**
* @generated
*/
//@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
@ManyToMany
(cascade =
{CascadeType.
PERSIST, CascadeType.
MERGE
}, fetch = FetchType.
LAZY, mappedBy=
"attachs"
)
private java.
util.
List
implambition.
forxxx.
model.
Product> products;
标签:product,hibernate,name,示例,FetchType,annotion,products,JoinTable,fetch
From: https://blog.51cto.com/u_16066979/6414238