我正在尝试将Hibernate用于多线程应用程序,其中每个线程检索一个对象并尝试将其插入表中.我的代码如下所示.我有每个线程的本地hibernate Session对象,并在每个InsertData中我做beginTransaction和commit.
我面临的问题是很多次我得到"org.hibernate.TransactionException:不支持嵌套事务"
由于我刚接触休眠,我不知道我在做什么是正确的还是不正确?请告诉我在多线程应用程序中使用hibernate的正确方法是什么,以及如何避免上述异常.
谢谢
public class Worker extends Thread {
private Session session = null;
Worker() {
SessionFactory sf = HibernateUtil.getSessionFactory(); // Singleton
session = sf.openSession();
session.setFlushMode(FlushMode.ALWAYS);
}
public void run() {
// Some loop which will run thousand of times
for (....)
{
InsertData(b);
}
session.close();
}
// BlogPost Table has (pk = id AutoGenerated), dateTime, blogdescription etc.
private void InsertData(BlogPost b) {
session.beginTransaction();
Long id = (Long) session.save(b);
b.setId(id);
session.getTransaction().commit();
}
}
Run Code Online (Sandbox Code Playgroud)
我的hibernate配置文件有c3p0.min_size=10
和c3p0.max_size=20
我正在集成spring-security-saml扩展以支持我的web应用程序中的SSO,我的应用程序应该允许不同的客户将他们的IDP元数据和他们的证书添加到我的webapp(这是一个SP),以便我的webapp可以启动SSO对他们的IDP.
现在我在我的java配置中定义了一个"元数据"bean,我将idp元数据添加到CachingMetadataManager中.但这只发生一次,我无法弄清楚如何在运行时向MetadataManager添加新的idp元数据(无需重新启动我的应用程序).我可以从Spring ApplicationContext获取元数据bean并为其添加新的提供程序吗?它会起作用吗?
使用spring-SAML支持上述用例(在运行时添加新的idp)的一般做法是什么?有没有其他支持这个的java库.
提前致谢
是否有任何开源库(JaveScript)在画布上实现偶数填充规则.如果我自己尝试实现它,那么它会有多复杂(考虑到具有复杂曲线的一般情况)并且它会影响性能(由于在JaveScript中为每个像素执行它的开销).
将偶数奇数填充转换为非零绕组的方法有哪些(考虑到适用于所有情况的通用解决方案).一旦我找到的方法是将形状划分为所有非交叉多边形并分别填充它们.
一种选择是使用SVG并在画布上绘制SVG,但我也发现原生SVG渲染在iPad上有点慢,但即使我在HTML画布上(在iPad上)绘制它也是SVG很慢?
提前致谢
我必须在画布上绘制描边填充。为此,我分别调用ctx.fill
和ctx.stroke
。因此,笔划的阴影绘制在填充的顶部,这是我想避免的。
有人可以告诉是否有办法避免这种情况吗?
这是我的代码:
ctx1.fillStyle = "blue";
ctx1.strokeStyle = "black";
ctx1.shadowColor = "rgba(0,255,0, 1)";
ctx1.shadowOffsetX = 50;
ctx1.shadowOffsetY = 50;
ctx1.lineWidth = "20";
ctx.beginPath();
ctx.moveTo(300, 100);
ctx.lineTo(400, 100);
ctx.lineTo(400, 200);
ctx.lineTo(300, 200);
ctx.closePath();
ctx1.fill();
ctx1.stroke();
Run Code Online (Sandbox Code Playgroud)
如果我们在AWS中拥有只能从专用子网中的EC2访问的MySQL RDS,那么从安全角度(使用默认RDS加密)对其进行加密是否有任何好处。因为某人访问DB的唯一方法是当他进入AWS的私有子网时,在那种情况下加密和不加密无济于事,因为无论如何黑客都可以从EC2访问数据。然后,唯一的区别就是加密RDS将使他花费更多时间转储数据并将其复制到其他地方以供他使用。否则,加密私有RDS实例还有什么其他好处?假设数据库的唯一备份是使用默认数据库实例备份的AWS本身,那么没有人也可以直接从数据库备份访问数据。
我在 AWS 上有以下设置
ELB(终止SSL)-> nginx 在80 上接收http 并转发到-> 8080 上的tomcat
但是当我在我的 servlet 中执行 response.sendRedirect("/somepath") 时,浏览器将它作为 302 http://example.com/somepath接收
但我希望浏览器获得https://example.com/somepath,我如何在 tomcat 或 nginx 中实现这一点而不在它们上设置 SSL。
我有以下spring-security.xml
<security:global-method-security proxy-target-class="true" secured-annotations="enabled" />
<security:http auto-config="false" use-expressions="true" entry-point-ref="customLoginEndpoint" >
<security:custom-filter ref="authenticationFilter" position="FORM_LOGIN_FILTER"/>
</security:http>
<bean id="authenticationFilter" class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"
p:authenticationManager-ref="customAuthenticationManager"/>
Run Code Online (Sandbox Code Playgroud)
下面是customLoginEndpoint
@Component("customLoginEndpoint")
public class CustomLoginEndpoint extends LoginUrlAuthenticationEntryPoint
{
public AcapLoginEndpoint()
{
super("/auth/login");
}
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authenticationException)
throws IOException, ServletException {
response.sendRedirect("/auth/login");
}
}
Run Code Online (Sandbox Code Playgroud)
我的控制器分类为@ExceptionHandler(Throwable ex)和带有@Secured批注的几种方法
问题是@ExceptionHandler方法捕获由@Secured批注引起的所有org.springframework.security.access.AccessDeniedException,因此请求永远不会到达CustomLoginEndpoint.commence并被拒绝。
如果我删除@ExceptionHandler,则一切正常。
我如何使它工作,以便调用begin并避免@ExceptionHandler捕获由于@Secured注释而导致的AccessDeniedException。
canvas ×2
html ×2
javascript ×2
amazon-elb ×1
hibernate ×1
java ×1
nginx ×1
saml-2.0 ×1
spring-saml ×1
ssl ×1
tomcat ×1