我已经阅读了一段时间关于Hibernate,但我似乎无法理解一个关于Hibernate的概念Transaction.
在我访问过的某些网站上,Select语句处于交易模式.
public List<Book> readAll() {
Session session = HibernateUtil.getSessionFactory()
.getCurrentSession();
session.beginTransaction();
List<Book> booksList = session.createQuery("from Book").list();
session.getTransaction().commit();
return booksList;
}
Run Code Online (Sandbox Code Playgroud)
在某些网站上,它并不主张在Select语句中使用事务:
public List<Book> readAll() {
Session session = HibernateUtil.getSessionFactory()
.getCurrentSession();
List<Book> booksList = session.createQuery("from Book").list();
return booksList;
}
Run Code Online (Sandbox Code Playgroud)
我在想我应该遵循哪一个.是否需要在Select报表上进行交易?
这里有Hibernate新手.我正在研究一个简单的Hibernate映射文件.当我使用xml方法时,我将生成器类设置为已分配.在分配员工ID之前必须检查某些逻辑,因此我无法自动生成它.
<id name="id" type="string" column="emp_id">
<generator class="assigned">
</generator>
</id>
Run Code Online (Sandbox Code Playgroud)
但我也正在研究注释类型和注释似乎是现在的事情,因为框架正在远离配置文件.但我找不到任何生成类型来匹配指定的值
public class Employee{
String id;
@column(name="emp_id", unique=true)
public String getID(){
return id;
}
}
Run Code Online (Sandbox Code Playgroud)
这是否意味着我在分配时不需要添加任何序列生成器注释?谢谢
我在会话中设置了一个会话范围对象,我想使用JSTL Ternary运算符在我的一个按钮中添加一个禁用属性.
getPermission是当前登录用户的权限映射,但我不确定为什么我unterminated c:out tag在JSP进入此JSP 时遇到错误.
<button type="button" id="addButton"
<c:out value="${empty sessionScope.voUserInfo.getPermission.ADD_ITEM ? "disabled='disabled'" : ''}"/> >
ADD
</button>
Run Code Online (Sandbox Code Playgroud) 我是用C++自学的,所以如果我的问题非常基本,我想请求你的原谅.
我正在关注www.learncpp.com上的教程
根据教程,我可以像这样定义我的c ++数组
int main()
{
using namespace std;
enum ArrayElements
{
MAX_ARRAY_SIZE = 5;
};
int anArray[MAX_ARRAY_SIZE];
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是代码块继续发出错误
||=== Build: Debug in CH6 (compiler: GNU GCC Compiler) ===|
In function 'int main()':|
|6|error: expected primary-expression before 'enum'|
error: expected ';' before 'enum'|
||=== Build failed: 2 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
Run Code Online (Sandbox Code Playgroud)
我只是不知道导致错误的是什么,或者我正在关注的教程是否存在问题?
我正在寻找一种如何使用gRPC实现文件下载功能的方法,但我在文档中找不到这是如何完成的.
这样做的最佳方式是什么?我想拥有一个保存文件的gRPC服务器和一个gRPC客户端来请求来自gRPC的东西.
我查看了Java中的示例,但无法找到如何执行此操作的方法.我今天刚开始阅读有关gRPC的内容.
我有这个写入/ temp/config的图像,我想将这些数据映射到我主机的共享卷中
docker-compose downversion: '2'
services:
service-test:
image: service-test:latest
container_name: service-test
volumes:
- source_data:/temp/config/
volumes:
source_data:
Run Code Online (Sandbox Code Playgroud)
当我的服务测试:最新图像尝试写入/ temp/config时,我收到一个Permission Denied错误.
问题,如何使此主机共享卷可写?
我使用了检查共享卷
docker volume inspect source_data
Run Code Online (Sandbox Code Playgroud)
我注意到它没有写入功能.这是一个基于Linux的发行版.
更新2: 为了验证这一点,我尝试检查共享卷上的权限,我发现它也没有写权限.
bash-4.2$ docker inspect volume service-test_source_data
[
{
"Driver": "local",
"Labels": null,
"Mountpoint": "/scratch/docker/volumes/service-test_source_data/_data",
"Name": "configservice-test_config_data",
"Options": {},
"Scope": "local"
}
]
bash-4.2$ ls -l /scratch/docker/volumes/service-test_source_data/
**drwxr-xr-x** 1 root root 0 Apr 18 01:43 _data
Run Code Online (Sandbox Code Playgroud) 我有一个像这样的控制器类,它将一些执行器传递到可运行实例中。这不是它的工作原理,但为了简单起见,我这样做了。
package com.test.executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Controller {
private ExecutorService executor;
public Controller() {
executor = Executors.newCachedThreadPool();
}
public void doRun() {
MyRunner runner = new MyRunner(executor);
Thread myRunner = new Thread(runner);
myRunner.start();
}
public static void main(String[] args) {
new Controller().doRun();
}
}
Run Code Online (Sandbox Code Playgroud)
运行程序接收执行程序的实例,然后传递某些可调用对象。现在,可调用对象有点不同,因为某些可调用对象访问数据库/调用某些 Web 服务/文件系统
我在如何为这种情况编写合适的 JUnit 方面遇到一些问题。我希望拥有尽可能多的代码覆盖率。
package com.test.executor;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
public class MyRunner implements Runnable {
private ExecutorService executor; …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过执行以下命令来构建我的cordova构建
cordova -d build android
Run Code Online (Sandbox Code Playgroud)
但我错误地发现了.
module.js:340
throw err;
Error: Cannot find module 'which'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
Run Code Online (Sandbox Code Playgroud)
谁知道原因?我检查了我的路径中有我的ANT_HOME/ANDROID_HOME,但我不确定错误背后的原因是什么.
顺便说一句,我正在运行Windows 7 64位
我有一个代码,将链接的哈希映射转储到YAML对象中
public class TestDump {
public static void main(String[] args) {
LinkedHashMap<String, Object> values = new LinkedHashMap<String, Object>();
values.put("one", 1);
values.put("two", 2);
values.put("three", 3);
DumperOptions options = new DumperOptions();
options.setIndent(2);
options.setPrettyFlow(true);
Yaml output = new Yaml(options);
File targetYAMLFile = new File("C:\\temp\\sample.yaml");
FileWriter writer =null;
try {
writer = new FileWriter(targetYAMLFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
output.dump(values, writer);
}
}
Run Code Online (Sandbox Code Playgroud)
但是输出看起来像这样
{
one: 1,
two: 2,
three: 3
}
Run Code Online (Sandbox Code Playgroud)
有没有办法将其设置为这样的事情
one: 1
two: 2 …Run Code Online (Sandbox Code Playgroud) 我有一个服务需要将文件流返回给调用客户端,所以我创建了这个 proto 文件。
service Sample {
rpc getSomething(Request) returns (stream Response){}
}
message Request {
}
message Response {
bytes data = 1;
}
Run Code Online (Sandbox Code Playgroud)
当服务器收到这个时,它需要读取一些 source.txt 文件,然后将其作为字节流写回客户端。只是想问一下这是在 Python GRPC 服务器中执行此操作的正确方法吗?
fileName = "source.txt"
with open(file_name, 'r') as content_file:
content = content_file.read()
response.data = content.encode()
yield response
Run Code Online (Sandbox Code Playgroud)
我找不到任何与此相关的示例。