有两张多对多关联表:
@Entity
@AccessType("field")
@Table(name="MENU")
public class Menu implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="menu_id")
private Long menuId;
@Column(name="menu_Name")
private String menuName;
/**
* 角色-菜单关联
*/
@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch=FetchType.LAZY)//合并
@JoinTable(name = "ROLE_MENU", joinColumns = { @JoinColumn(name = "menu_id") }, inverseJoinColumns = { @JoinColumn(name = "role_id") })
// @PersistenceContext(type = PersistenceContextType.EXTENDED)
private Set<Role> roles = new LinkedHashSet<Role>();
public Set<Role> getRoles() {
return roles;
}
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
}
和
@Entity
@AccessType("field")
@Table(name="ROLE")
public class Role implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="role_id")
private Long roleId;
@Column(name="role_Name")
private String roleName;
/**
* 角色-菜单关联
*/
@ManyToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.LAZY)
@JoinTable(name = "ROLE_MENU", joinColumns = { @JoinColumn(name = "role_id") }, inverseJoinColumns = { @JoinColumn(name = "menu_id") })
private Set<Menu> menus = new LinkedHashSet<Menu>();
public Set<Menu> getMenus() {
return menus;
}
public void setMenus(Set<Menu> menus) {
this.menus = menus;
}
}
注意:一定要两张表分别@JoinTable(name = "ROLE_MENU")
在Role在引用menus的时候,报:org.hibernate.LazyInitializationException: failed to lazily initial
解决办法:roleDao.getHibernateTemplate().initialize(role.getMenus());
当关联表中不存在此记录时,role.getMenus();将会报错:org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
解决办法:加上 @NotFound(action = NotFoundAction.IGNORE)
分享到:
相关推荐
stream.js 是一个很小、完全独立的Javascript类库,它为你提供了一个新的...他的这种魔力来自于具有延后(lazily)执行的能力。这简单的术语完全能表明它们可以加载无穷多的元素。(http://www.aqee.net/docs/stream/)
lazily. Copyright (c) 2009 Armando Blancas. All rights reserved. The use and distribution terms for this software are covered by the Eclipse Public License 1.0 ...
/ specific area difficult, so I lazily redraw almost the whole control whenever / it needs. This results in the slowness (I suggest you can use the control in data / display, ^_^). In next version,...
Slicing rows lazily Getting ready How to do it... How it works... There's more... Slicing lexicographically Getting ready How to do it... How it works... There's more... 5. Boolean Indexing ...
`lazily`:金鱼慵懒地(lazily)成群结队地在水面下游动。 - 15. `coats`:他们给前门刷了三层(coats)油漆。 2. **关键短语或词组**: - 1. `come along`:一起来,过来。 - 2. `a novel called…`:一本叫做...
10. 系动词与形容词:"said lazily",系动词said后接形容词lazily,表示懒洋洋地说。 11. 听到某人的话:"When hearing these words",现在分词短语作时间状语。 12. 介词短语:"to his surprise",介词短语表示令他...
2. 形容词转副词,如lazy变为lazily,常用来修饰动词。 3. 数词转换为序数词,如twenty变为twentieth,表示顺序。 4. 名词转形容词,如dirt变为dirtY,用以形容事物的状态。 5. 名词转形容词,如sun变为sunny,描述...
spring.servlet.multipart.resolve-lazily=false ``` 在实际应用中,为了处理文件上传,我们需要创建一个Controller,它会接收前端发送的文件。`MultipartFile`是Spring提供的接口,用于处理文件上传请求。以下是一...
6. **词汇积累**:文档中的词汇如"lazily bathed"、"desperately brainstorming"、"relish the pleasure"等,都是对学生词汇量和词汇运用的检验。 7. **句型结构**:例如"Only then did we realize we should ...
npm install --save react-lazily-render 用法 () import React from 'react' ; import LazilyRender from 'react-lazily-render' ; ...lots of content... < LazilyRender xss=removed> } content = { ...
7. **副词的使用**:F部分提供了几个副词,如slowly(慢地)、lazily(懒散地),这些词修饰动词,表示动作的方式。 8. **将来时态**:G部分中,用will表示将来时态,如"He'll...",表明将要发生的动作。 9. **...
包括选择合适的图片格式(如WebP)、压缩图片大小、利用惰性加载(Lazily load images)等技术。 综上所述,"安卓 image"涉及了Android开发中的图像资源管理、菜单设计、全屏模式的实现以及图像的显示和处理等多个...
- ` Lazily loaded images`:利用`loading="lazy"`属性延迟加载图片。 开放式问题涉及的技能和流程,如JavaScript延迟加载技术、关注的技术趋势、开发流程与使用的工具、网站性能优化策略、原型继承和闭包的理解等...
Lazily instantiate your dependencies when needed Stop caring about dependency initialization order Easily bind classes or interfaces to their instance or provider Easily debug your dependency bindings...
committed, the command line prompt script failed to notice the current status, which has been improved. * Many GIT_TEST_* environment variables control various aspects of how our tests are run, ...
HibernateTransactionManager (unintentionally) bound to Hibernate 5.2 SharedSessionContractImplementor [SPR-17557] #22089 Spring JavaMailSenderImpl does not show proper message when recipient list is ...
- **Deferred Execution**: Explains how LINQ queries are executed lazily, only when the results are enumerated. - **Joining and Grouping Collections**: Demonstrates how to combine and group data ...
-- data-qazy is set to true means to load it lazily. Set it to false if you don't want to load it lazily. --> <!-- A default placeholder is used. To change the placeholder, assign the variable ...
11. **错误处理**:为了确保网站的健壮性,开发者可能使用try-catch语句捕获并处理错误,或集成 Sentry 等错误追踪服务。 12. **SEO优化**:对于GitHub Pages上的静态站点,可能使用了如Jekyll、Hugo或Gatsby这样的...
Redis 的过期策略是惰性删除(Lazily Expired)和定期删除(Periodic Checking)相结合,保证了内存的有效利用和性能的平衡。 总结来说,Redis 的事务和过期时间是两个关键特性,它们提供了数据的原子性和时效性...