小编HDJ*_*MAI的帖子

Hibernate无法获取当前线程的事务同步会话

我遇到过类似的问题,就像许多人一直有的一样,但我似乎无法弄清楚在我的具体案例中出了什么问题.我正在进行一个简单的数据库调用来测试数据库连接,Hibernate抛出以下异常:

Exception in thread "main" org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:134)
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014)
at boardwalk.computeServer.dao.DbDaoHibernateImpl.getInterpolationJob(DbDaoHibernateImpl.java:73)
at boardwalk.computeServer.ComputeServer.test(ComputeServer.java:39)
at boardwalk.computeServer.ComputeServer.main(ComputeServer.java:32)
Run Code Online (Sandbox Code Playgroud)

以下是相关代码和配置:

pom.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema  instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-    4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>boardwalk</groupId>
  <artifactId>computeServer</artifactId>
  <version>1.0</version>
  <packaging>jar</packaging>

  <name>marketserver</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>4.1.1.RELEASE</version>
  </dependency>
  <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.33</version>
  </dependency>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>4.1.1.RELEASE</version>
  </dependency>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    <version>4.1.1.RELEASE</version>
  </dependency>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>4.1.1.RELEASE</version>
  </dependency>
  <dependency>
    <groupId>javax.transaction</groupId> …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate transactions

12
推荐指数
2
解决办法
4万
查看次数

unordered_set&lt;int&gt; find 方法的时间复杂度

find方法的时间复杂度是多少unordered_set<int>

还可以更改哈希函数吗?

stl time-complexity unordered-set c++11

12
推荐指数
1
解决办法
2万
查看次数

使用ngx-bootstrap modalService时添加自定义类的方法

在这里查看ngx-bootstrap 源代码时:

莫代尔,options.class.ts

有一个可选的class property定义为class?: string;.

使用它的方法是什么?

是否可以添加自定义类,如:

this.modalService.config.class = 'myClass';
Run Code Online (Sandbox Code Playgroud)

在使用servive之前,例如:

this.modalRef = this.modalService.show(template, {
  animated: false
});
Run Code Online (Sandbox Code Playgroud)

这样,我认为我们可以将自定义CSS添加到显示的模态中

最佳实践或示例是什么?

我试图添加自定义类但没有成功

该类属性不是数组,如果适用,是否意味着我们只能添加一个自定义类?

演示:通过添加和覆盖modal类,模式不显示

https://stackblitz.com/edit/ngx-bootstrap-3auk5l?file=app%2Fapp.component.ts

modal这种方式添加类没有帮助:

this.modalRef = this.modalService.show(template, Object.assign({},
                this.config, { class: 'gray modal-lg modal' }));
Run Code Online (Sandbox Code Playgroud)

https://stackblitz.com/edit/ngx-bootstrap-awmkrc?file=app%2Fapp.component.ts

css ngx-bootstrap angular ngx-bootstrap-modal

12
推荐指数
1
解决办法
9241
查看次数

无法构建R包"png"Fedora 20

我正在尝试构建R软件包png,repo说libpng需要提供.

我运行Linux Fedora 20发行版

看起来我有它......

[root@localhost bin]# yum install libpng
Loaded plugins: langpacks, refresh-packagekit
Package 2:libpng-1.6.3-3.fc20.x86_64 already installed and latest version
Nothing to do
Run Code Online (Sandbox Code Playgroud)

但是当我尝试安装它时:

> install.packages("png")
Installing package into ‘/home/statquant/R/x86_64-redhat-linux-gnu-library/3.0’
(as ‘lib’ is unspecified)
trying URL 'http://cran.rstudio.com/src/contrib/png_0.1-7.tar.gz'
Content type 'application/x-gzip' length 24990 bytes (24 Kb)
opened URL
==================================================
downloaded 24 Kb

* installing *source* package ‘png’ ...
** package ‘png’ successfully unpacked and MD5 sums checked
** libs
gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG …
Run Code Online (Sandbox Code Playgroud)

install r libpng fedora20

11
推荐指数
2
解决办法
8885
查看次数

创建虚拟函数的纯虚函数是危险的吗?

让我们假设我们有一个抽象类NonEditableSuperBase,我们从中创建另一个抽象类MyBase.

第一类NonEditableSuperBase具有虚函数(非纯虚).但是,我想强制说,如果某人创建了一个派生的类MyBase,他/她必须为所提到的函数提供一个实现.

因此,我的想法是将函数定义为纯虚拟MyBase.

我的问题:鉴于它只是虚拟的,这是一个坏主意NonEditableSuperBase吗?

例:

//NonEditableSuperBase.h
class NonEditableSuperBase
{
  ...
  public:
    virtual int someMethod(); //It has an implementation, suppose {return 42;}
};

//MyBase.h
class MyBase: public NonEditableSuperBase
{
  public:
     explicit MyBase();       
     virtual ~MyBase() = default;       
     virtual int someMethod() = 0;  //I make it pure virtual
};

//MyBase.cpp
MyBase::MyBase() : NonEditableSuperBase() { }

//Now someone creates a derived class from MyBase.
class SuperDerived : public MyBase
{
  public: …
Run Code Online (Sandbox Code Playgroud)

c++ abstract-class pure-virtual

11
推荐指数
1
解决办法
638
查看次数

Angular 双向数据绑定和观察父组件的变化

使用双向数据绑定时,似乎没有办法观察父组件的变化。

我有一个用于收集标签列表的自定义输入组件。双向数据绑定在此组件与其父组件之间设置和工作。

// the parent component is just a form
// here is how I'm adding the child component
<input-tags formControlName="skillField" [(tags)]='skillTags' (ngModelChange)="skillTagUpdate($event)">
</input-tags>
Run Code Online (Sandbox Code Playgroud)

在父组件中,如何观察绑定变量的变化?虽然它总是最新的(我已经确认了这一点),但我找不到任何关于对变化做出反应的指导。

我试过了:

ngOnChanges(changes: SimpleChanges) {
    if (changes['skillTags']) {
        console.log(this.skillTags);  // nothing
    }
}
Run Code Online (Sandbox Code Playgroud)

skillTagUpdate(event){
    console.log(event); // nothing
}
Run Code Online (Sandbox Code Playgroud)

更新: TWDB 恕我直言不是它所宣传的那样。每当我到达 TWDB 似乎是一个解决方案的地方时,我都会重新设计服务和/或可观察的通信。

eventemitter angular two-way-binding controlvalueaccessor

11
推荐指数
2
解决办法
5580
查看次数

COMMIT或conn.setAutoCommit(true)

我注意到一些程序员使用COMMIT其他使用conn.setAutoCommit(true);来结束事务或回滚所以使用一个而不是另一个有什么好处?

主要区别在哪里?

conn.setAutoCommit(true);
Run Code Online (Sandbox Code Playgroud)

过度

statement.executeQuery(query);
statement.commit();
Run Code Online (Sandbox Code Playgroud)

java mysql jdbc percona

10
推荐指数
2
解决办法
3万
查看次数

Bash Anonymous Pipes

在设计一系列命令来执行某项任务时,我遇到了匿名管道不像预期的那样行为的问题.由于我正在运行的原始命令太复杂而无法在此解释,我创建了一个显示问题的示例(我知道所有这些命令基本上都没有做).另外,我使用pv来显示数据是否实际上是从输入复制到输出.

cat /dev/zero | pv > /dev/null
Run Code Online (Sandbox Code Playgroud)

这按预期工作.(将数据从/ dev/zero复制到/ dev/null)

cat /dev/zero | tee /dev/null | pv > /dev/null
Run Code Online (Sandbox Code Playgroud)

这也按预期工作(复制数据并将两个副本发送到/ dev/null)

cat /dev/zero | tee >(pv -c > /dev/null) | pv -c > /dev/null
Run Code Online (Sandbox Code Playgroud)

此命令仅部分有效.虽然从STDIN到STDOUT的副本仍然可以工作,(一个pv会在短时间内显示进度),整个命令会被匿名管道停止,它不会收到任何东西,因此tee停顿,因为其中一个输出无法写入(我通过让它写入文件而不是/ dev/null来检查这一点).

如果有人知道为什么这不起作用(如预期的那样?)在bash中,我会很高兴得到帮助.

PS:如果我使用zsh而不是bash,则命令按预期运行.不幸的是,这个需要运行的系统没有zsh,我无法在部署的系统上获得zsh.

linux bash pipe anonymous-pipes

10
推荐指数
1
解决办法
1915
查看次数

升级到IntelliJ 2017.1后,类JavaLaunchHelper错误

我刚刚更新到IntelliJ IDEA 2017.1,现在我每次都在运行时收到此错误消息:

objc [3318]:类JavaLaunchHelper在/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/bin/java(0x107a4c4c0)和/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/中实现. Contents/Home/jre/lib/libinstrument.dylib(0x107b144e0).将使用两者之一.哪一个未定义.

一切都像往常一样.看起来真的很烦人.我在旧版本的IntelliJ之前没有此错误消息.

如果没有修复,那么我可以告诉IntelliJ在运行我的程序时没有给我这个特定错误吗?

java upgrade intellij-idea

10
推荐指数
0
解决办法
883
查看次数

Spring AOP没有@EnableAspectJAutoProxy可以工作吗?

我正在学习Spring(当前是其AOP框架)。即使我阅读过的所有消息都说要启用AOP,也需要使用@EnableAspectJAutoProxy注释(或其XML副本),但我的代码似乎可以注释掉注释。那是因为我使用Lombok还是Spring Boot(v。1.5.9.RELEASE,取决于Spring v。4.3.13.RELEASE)?

最小的示例如下:

build.gradle

buildscript {
    ext {
        springBootVersion = '1.5.9.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'org.springframework.boot'

group = 'lukeg'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter')
    compileOnly('org.projectlombok:lombok')
    compile("org.aspectj:aspectjweaver:1.8.11")
    testCompile('org.springframework.boot:spring-boot-starter-test')
}
Run Code Online (Sandbox Code Playgroud)

ApplicationConfiguration.java(请注意,AOP注释已被注释掉)

package lukeg;

import org.springframework.context.annotation.*;

@Configuration
@ComponentScan
//@EnableAspectJAutoProxy
public class ApplicationConfiguration {
    @Bean
    TestComponent testComponent() {
        return new TestComponent();
    }
}
Run Code Online (Sandbox Code Playgroud)

LearnApplication.java

package lukeg;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import …
Run Code Online (Sandbox Code Playgroud)

java spring aspectj spring-aop

9
推荐指数
1
解决办法
8231
查看次数