我对Hibernate很新.我发现我们可以使用以下两种不同的方式获得不同的结果.谁能告诉我他们之间有什么区别?何时使用其他?
Projections.distinct(Projections.property("id"));
Run Code Online (Sandbox Code Playgroud)
VS
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
Run Code Online (Sandbox Code Playgroud) 我做了一些研究,但找不到我要寻找的确切答案。目前我有一个主键列“id”,它设置为串行,但我想将其更改为 bigserial 以映射到 Java 层中的 Long。考虑到这是一个现有的表,实现这一目标的最佳方法是什么?我认为我的 Postgres 版本是 10.5。我也知道 serial 和 bigserial 都不是数据类型。
使用 SQL 很容易做到这一点,但我需要编写一个我不熟悉的 Knex 迁移脚本。以下将在表order_id中的行末尾添加列order。我想order_id在之后添加id。我怎么做?
const TABLE_NAME = 'order';
exports.up = function (knex) {
return knex.schema.alterTable(TABLE_NAME, table => {
table
.specificType('order_id', 'char(10)')
.unique()
.notNullable();
});
};
exports.down = function (knex) {
return knex.schema.table(TABLE_NAME, function (t) {
t.dropColumn('order_id');
});
};
Run Code Online (Sandbox Code Playgroud) 我知道不久前有人从PostgreSQL sum typecasting 作为 bigint提出了同样的问题,但我没有看到有人回答。我正在使用 sum 函数添加类型为整数的列的值,但是当我添加两个 15 亿时它会溢出。我希望总和结果为 bigint。有没有办法实现它?提前致谢。我尝试跟随但没有奏效。
sum(count)::bigint AS total
Run Code Online (Sandbox Code Playgroud)
如果我按照以下操作,我仍然收到错误 sum(count::bigint) AS total
Caused by: org.postgresql.util.PSQLException: ERROR: cannot change data type of column "total" from integer to numeric
Run Code Online (Sandbox Code Playgroud) 以下是一些代码的一部分.我需要在finally子句中关闭资源.我需要先调用closeEntry()还是close()?我收到一些错误消息.
Error closing the zipoutjava.io.IOException: Stream closed at
java.util.zip.ZipOutputStream.ensureOpen(ZipOutputStream.java:70) at
java.util.zip.ZipOutputStream.closeEntry(ZipOutputStream.java:189)
Run Code Online (Sandbox Code Playgroud)
代码
ZipOutputStream zos = null;
try{
ZipEntry entry = new ZipEntry("file.csv")
zipout.putNextEntry(entry);
csvBeanWriter = new CsvBeanWriter(writer,
CsvPreference.STANDARD_PREFERENCE);
csvBeanWriter.writeHeader(header);
for (Book book : bookList) {
csvBeanWriter.write(book, header);
csvBeanWriterTest.write(book, header);
}
} catch (Exception e) {
logger.error("Export of package data failed: "
+ e);
} finally {
if (zipout != null) {
try {
zos.closeEntry();
zos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
logger.error("Error closing the zos"
+ …Run Code Online (Sandbox Code Playgroud) 我有一个简单的 Springboot 应用程序并且它正在运行。我可以通过 Postman 调用 REST 端点。但是,当我尝试使用 http://localhost:8080/h2 访问控制台时,它一直返回 404。
2020-08-29 08:06:37.577 INFO 6507 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2020-08-29 08:06:37.644 INFO 6507 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.2.17.Final}
2020-08-29 08:06:37.645 INFO 6507 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2020-08-29 08:06:37.677 INFO 6507 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2020-08-29 08:06:37.787 INFO 6507 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2020-08-29 …Run Code Online (Sandbox Code Playgroud) postgresql ×2
distinct ×1
h2 ×1
hibernate ×1
java ×1
knex.js ×1
migration ×1
nhibernate ×1
spring-boot ×1
sum ×1