hibernate中使用clone()方法!求解!

chaohua20 chaohua20 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我在弄security但是延时加载的时候出现问题了!no session or session is close 没有session或者session关闭我先把代码帖出来大家看看!网上有人说要加个clone()这个方法能够解决问题!但是他又没帖怎么用!求高手解答!请不要告诉我OpenSessionInViewFilter坦白的告诉你们这个没有用!也许是security资源查询的顺序为最前,而这个拦截器还没造好吧!
上代码
实体类对象我是用注解实现的!

package com.onionbbs.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name="Resources")
public class Resources {
@Id
@GeneratedValue
@SequenceGenerator(name="ResourcesSequence")
@Column(name="id")
private int id;
@Column(name="name",length=30)
private String name;
@Column(name="url",length=255)
private String url;
@Column(name="Enabled")
private int Enabled;
@Column(name="isSystem")
private int isSystem;

@JoinTable(name="role_resource",inverseJoinColumns=@JoinColumn(name="resources_id"),joinColumns=@JoinColumn(name="role_id"))
@ManyToMany(cascade=CascadeType.REFRESH,fetch = FetchType.EAGER)
private Set<Role> role=new HashSet<Role>();

public Set<Role> getRole() {
return role;
}
public void setRole(Set<Role> role) {
this.role = role;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public int getEnabled() {
return Enabled;
}
public void setEnabled(int enabled) {
Enabled = enabled;
}
public int getIsSystem() {
return isSystem;
}
public void setIsSystem(int isSystem) {
this.isSystem = isSystem;
}

public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}

数据访问层

package com.OnionEntertainment.Security.Dao;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;

import com.onionbbs.model.Resources;

public class SecurityResourceDaoImp implements SecurityResourceDao{
private HibernateTemplate hibernateTemplate;

public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}

@SuppressWarnings("unchecked")
public List<Resources> getAllResources() {

return this.hibernateTemplate.find(" from "+Resources.class.getName());

}

}



业务层代码,会不会是我用的是注解的事务引起的呢?

package com.OnionEntertainment.Security.Service;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.OnionEntertainment.Security.Dao.SecurityResourceDaoImp;
import com.onionbbs.model.Resources;
@Transactional
public class SecurityResourceServiceImp implements SecurityResourceService{
private SecurityResourceDaoImp securityResourcesDao;


public void setSecurityResourcesDao(SecurityResourceDaoImp securityResourcesDao) {
this.securityResourcesDao = securityResourcesDao;
}

public List<Resources> getAllResources() {

return securityResourcesDao.getAllResources();
}


}

最后是在这里延时加载数据的这个是security的加载资源的一个类,在服务一启动的时候就开始加载数据库中的资源对象。

package com.onionbbs.security;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityConfig;
import org.springframework.security.web.FilterInvocation;
import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
import org.springframework.security.web.util.AntUrlPathMatcher;
import org.springframework.security.web.util.UrlMatcher;

import com.OnionEntertainment.Security.Service.SecurityResourceServiceImp;
import com.onionbbs.model.Resources;
import com.onionbbs.model.Role;


public class InvocationSecurityMetadataSource
implements FilterInvocationSecurityMetadataSource {

private UrlMatcher urlMatcher = new AntUrlPathMatcher();;
private static Map<String, Collection<ConfigAttribute>> resourceMap = null;


private SecurityResourceServiceImp securityResourceService;

public void setSecurityResourceService(
SecurityResourceServiceImp securityResourceService) {
this.securityResourceService = securityResourceService;
}





public void loadResourceDefine() {

resourceMap = new HashMap<String, Collection<ConfigAttribute>>();

for(Resources item:securityResourceService.getAllResources()){

resourceMap.put(item.getUrl(), listRoleToCollection(item.getRole()));

//也就是在这个地方进行加载资源所对应的权限的item.getRole()的
}
}


求高手解答这个问题,到底是用clone()方法呢?还是使用别的方法能够解决。是用clone()方法该怎么使用?添加在哪里?

...全文

相关推荐

hibernate.org:hibernate.org网站的资源-html source website

如何建立hibernate.org 一点点的Git,一点点的Ruby,您就会得到本地的hibernate.org服务。 目录 获取来源 > git clone git@github.com:hibernate/hibernate.org.git > cd hibernate.org 设置构建环境-简单的方法 设置构建环境的最简单方法是使用docker。 参见 。 设置构建环境-困难的方法 先决条件 获取 获取 > 1.9 确保已安装耙 确保可用。 它通常是默认安装的。 > rake --version 如果得到“找不到命令”: > gem install rake 确保已安装捆绑器 确保 (版本> = 1.10)可用。 它在项目本地管理您的Ruby gem,并防止不同Ruby项目之间的版本冲突。 从网站报价: Bundler通过跟踪和安装所需的确切gem和版本,为Ruby项

Tsy.H

spring-boot-postgresql-jpa-hibernate-rest-api-demo:使用Spring Boot,PostgreSQL,JPA和Hibernate构建RESTful API

Spring Boot,PostgreSQL,JPA,Hibernate REST API演示 讲解 在CalliCoder博客上查看完整的教程- 设定步骤 1.克隆存储库 git clone https://github.com/callicoder/spring-boot-postgresql-jpa-hibernate-rest-api-demo.git 2.配置PostgreSQL 首先,创建一个名为postgres_demo的数据库。 然后,打开src/main/resources/application.properties文件,并根据PostgreSQL安装更改spring数据源的用户名和密码。 3.运行应用 从项目的根目录中键入以下命令以运行它- mvn spring-boot:run 另外,您可以将应用程序打包为JAR文件的形式,然后像这样运行它- mvn clean package java -jar target/postgres-demo-0.0.1-SNAPSHOT.jar

火石创造

RentLio:这是车辆预订系统。 这是用JavaFX制作的,还使用了Hibernate和RMI

伦里奥 这是车辆预订系统。 它是用JavaFX制作的,还使用了Hibernate和RMI。 还有现代UI和UX概念以及 。 用户界面-行为 入门 克隆存储库。 git clone https://github.com/Shehanka/RentLio.git 安装 OpenJDK 11.0 或更高版本。 安装MySQL。 运行MySQL脚本。 运行mvn install 在RentLioClient上运行mvn exec:java 。 运行 RentLIOStart.java。 输入登录凭据。 最后给出一个从系统中取出一些数据或将其用于一些演示的示例 使用的设计模式 MVC 工厂 抽象工厂 辛格尔顿 观察者 正面 部署方式 创建JAR文件并执行 建于 jfoenix-使用的JavaFX框架 CustomStage-一个可以完全定制的JavaFX未经修饰的阶段 贡献 Cha

六演

accs-mongodb:使用Oracle应用容器云的MongoDB + Hibernate OGM快速入门

使用Oracle应用容器云的MongoDB + Hibernate OGM快速入门 查看以获取详细信息 建立 git clone https://github.com/abhirockzz/accs-mongodb.git mvn clean install acc-mongodb-dcs-dist.zip mvn clean install -在target目录中创建acc-mongodb-dcs-dist.zip 部署 使用Developer Cloud-阅读 在使用下面提到的选项进行部署之前,请确保使用正确的MongoDB坐标更新了 使用应用程序容器云 使用应用程序容器云 使用应用

Ma Daniel

gesg_clone

gesg_clone

Mika.w
评论 3
收藏 已收藏
分享
返回顶部
chaohua20
Java EE 67,535 成员 225,843 内容