我有一个Rental具有以下userId字段的实体:
@Column(name = "user_id", updatable = false, nullable = false)
private UUID userId;
Run Code Online (Sandbox Code Playgroud)
我也有一个JpaRepository:
public interface RentalRepository extends JpaRepository<Rental, UUID> {
@Query("FROM Rental r WHERE (:userId IS NULL OR r.userId = :userId) AND (:status IS NULL OR r.status = :status)")
Page<Rental> findAllUsingFilterUserIdAndStatus(@Param("userId") UUID userId,
@Param("status") RentalStatus status,
Pageable pageable);
}
Run Code Online (Sandbox Code Playgroud)
当我将userId作为 null 传递时,出现以下错误:
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:280)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:254) …Run Code Online (Sandbox Code Playgroud) 技术:
错误:
nested exception is org.springframework.dao.DataIntegrityViolationException: **could not execute statement; SQL [n/a]; constraint [null];**
java.sql.SQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`emr`.`user_detail`, CONSTRAINT `user_detail_ibfk_1` FOREIGN KEY (`id`) REFERENCES `facility` (`id`))
Run Code Online (Sandbox Code Playgroud)
DDL:
nested exception is org.springframework.dao.DataIntegrityViolationException: **could not execute statement; SQL [n/a]; constraint [null];**
java.sql.SQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`emr`.`user_detail`, CONSTRAINT `user_detail_ibfk_1` FOREIGN KEY (`id`) REFERENCES `facility` (`id`))
Run Code Online (Sandbox Code Playgroud)
Java类:
create table …Run Code Online (Sandbox Code Playgroud) 我必须处理声明如下的视图(Oracle 11g):
create view V_SOME_VIEW as
select X, Y
from SOME_TABLE
Run Code Online (Sandbox Code Playgroud)
和它的实体:
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
@Entity
@Table("V_SOME_VIEW")
@NamedQueries({
@NamedQuery(name = "VSomeView.findAll", query = "SELECT v FROM VSomeView v")})
public class VSomeView implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Lob
@Column(name = "X")
private Object x;
@Lob
@Column(name = "Y")
private Object y;
...
}
Run Code Online (Sandbox Code Playgroud)
使用Gradle Metamodel Plugin生成静态元模型后,我有以下没有属性 y 的元模型: …
有时,Hibernate 在持久操作期间似乎随机执行这样的查询:
select currval('MY_TABLE_NAME_id_seq');
Run Code Online (Sandbox Code Playgroud)
实体:
@Entity
@Table(name = "MY_TABLE_NAME")
public class MyEntity {
@Id
@Column(name = "ID", unique = true, nullable = false)
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
}
Run Code Online (Sandbox Code Playgroud)
代码:
@Transactional
public void persistMyEntity(String name) {
MyEntity entity= new MyEntity (name);
sessionFactory.getCurrentSession().persist(entity);
}
Run Code Online (Sandbox Code Playgroud)
生成的sql:
insert into MY_TABLE_NAME(name) values ('xyz');
select currval('MY_TABLE_NAME_id_seq');
Run Code Online (Sandbox Code Playgroud)
但通常select currval不会被执行。对此有什么解释吗?
顺便说一句,我的问题与此非常相似,但问题中的解决方案对我不起作用。
笔记:
My_TABLE_NAME ddl sql:
CREATE TABLE my_table_name (
id bigserial NOT NULL,
name character varying(256) NOT NULL,
CONSTRAINT my_table_name_id PRIMARY KEY (id)
);
Run Code Online (Sandbox Code Playgroud)
休眠特性: …
我无法找到如何在 Spring Boot 应用程序中为不同数据库映射不同类型的字段。首先,我想知道如何映射 MySQL 时间戳,但如果我还可以找到不同数据库中每种数据类型的映射集合的链接,那就太好了。
我刚刚安装了node.js v14。当我构建 Angular 9 包时,我收到了这些警告。
\nng build \xe2\x80\x93prod myPackage\n\n(node:14432) Warning: Accessing non-existent property 'lineno' of module exports inside circular dependency\n(Use `node --trace-warnings ...` to show where the warning was created)\n(node:14432) Warning: Accessing non-existent property 'column' of module exports inside circular dependency\nRun Code Online (Sandbox Code Playgroud)\n我想知道如何使用node \xe2\x80\x93trace-warnings来查找抛出错误的位置。
我正在使用 Angular 9。
\n我的数据库中有一张带有主组合键的表,当我使用 Hibernate 对其进行建模时,我使用@EmbeddedId& @Embedable。该复合主键的一列具有带有 的生成值@GeneratedValue(strategy = GenerationType.IDENTITY)。
当我尝试在数据库中创建两个新对象时,出现如下错误:
org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [MyPackage#MyEmbedableClass [MyGeneratedPrimaryKeyValue=null, OtherPrimaryKey=21]]
Run Code Online (Sandbox Code Playgroud)
但是当我查看数据库时,我的对象已创建。我不明白我的错误,我不知道如何解决我的问题。
我找到了一些像我这样的主题,但还没有找到我的问题的答案。
org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [MyPackage#MyEmbedableClass [MyGeneratedPrimaryKeyValue=null, OtherPrimaryKey=21]]
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助。
下面是可排序的 jquery 代码,它在 dasktop 中工作正常,但在移动浏览器中无法工作,所以请建议如何解决...?
$(document).ready(function() {
$("#post_list").sortable({
placeholder: "ui-state-highlight",
handle: ".socialmediaspacing",
delayOnTouchOnly: true,
update: function(event, ui) {
var post_order_ids = new Array();
$('#post_list div.listitems').each(function() {
post_order_ids.push($(this).data("post-id"));
});
$.ajax({
url: "url",
method: "POST",
data: {
post_order_ids: post_order_ids,
"_token": "{{csrf_token()}}"
},
success: function(data) {
$('#socail-profile-mobileview').html(data);
Snackbar.show({
pos: 'bottom-right',
text: "Ordering changed successfully.",
actionText: 'Okay'
});
}
});
}
});
$( "#post_list" ).disableSelection();
});
Run Code Online (Sandbox Code Playgroud) 以下是我的文件的内容log4j2.properties。它打印sql但不打印参数。如何添加org.hibernate.type=trace或类似打印参数?
appenders = console, file
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
appender.file.type = File
appender.file.name = File
appender.file.fileName = app.log
appender.file.layout.type = PatternLayout
appender.file.layout.pattern = [%-5level] %d{dd-MM-yyyy HH:mm:ss.SSS} [%t] %c{1} - %msg%n
rootLogger.level = info
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT
rootLogger.appenderRef.file.ref = File
logger.hibernate.name=org.hibernate.SQL
logger.hibernate.level=debug
Run Code Online (Sandbox Code Playgroud)