hibernate

Deleting entity in Spring JPA

这一生的挚爱 提交于 2020-12-13 03:10:20
问题 There are two entities with relation @ManyToOne and @OneToMany (Categories and Products). When I enabeling (cascade=CascadeType.ALL) one record in Products pulls for deleting one Category, and that is BAD. What must be do for this entities that result is only deleting occurs in one place(Table) without cascade(related) delete for another reference??? I am using Spring 5.1.5 (not Spring Boot) Thank you! SPRING 5 / TOMCAT 9 / JACKSON-DATABIND / spring-data-jpa 2.1.5 / persistence-api 1.0.2 /

not to create revision for particular column change

自古美人都是妖i 提交于 2020-12-13 00:45:48
问题 I have a model that is audited and there is a column in it that I have to update periodically. Bu I don't want to create revision for every change of this column. Is there any configuration for not to create revision even if the property X's been changed? 回答1: The only out-of-the-box way to do what you ask is to implement Conditional Auditing . The conditional auditing approach described in the documentation requires that users provide their own event listeners and add your various if-checks

not to create revision for particular column change

ⅰ亾dé卋堺 提交于 2020-12-13 00:45:13
问题 I have a model that is audited and there is a column in it that I have to update periodically. Bu I don't want to create revision for every change of this column. Is there any configuration for not to create revision even if the property X's been changed? 回答1: The only out-of-the-box way to do what you ask is to implement Conditional Auditing . The conditional auditing approach described in the documentation requires that users provide their own event listeners and add your various if-checks

【已解决】NoSuchMethodError: org.hibernate.SessionFactory.getCurrentSession()...

限于喜欢 提交于 2020-12-12 21:22:09
首先贴错误日志:解决方案见最下方 java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:450) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:289) at com.opensymphony.xwork2.DefaultActionInvocation

hql 使用query.list()为空指针异常 ,但是数据库可以查出结果

落爺英雄遲暮 提交于 2020-12-12 12:47:15
hql 使用query.list() 为空指针异常 ,但是数据库可以查出结果 解决方法: hibernate配置中检查数据库的方言是否配置正确 org.hibernate.dialect.OracleDialect < property name = "hibernateProperties" > < props > < prop key = "hibernate.dialect" > org . hibernate . dialect . OracleDialect < / prop > < prop key = "hibernate.show_sql" > true < / prop > < prop key = "dynamic-update" > true < / prop > < prop key = "hibernate.jdbc.batch_size" > 0 < / prop > < / props > < / property > 给出常见数据库方言 RDBMS 方言 DB2 org.hibernate.dialect.DB2Dialect DB2 AS/400 org.hibernate.dialect.DB2400Dialect DB2 OS390 org.hibernate.dialect.DB2390Dialect PostgreSQL org

How to autoincrement an Id in a composite primary key in Hibernate?

谁说胖子不能爱 提交于 2020-12-09 09:54:15
问题 I have a table with a composite primary key - groupId and batchId . Entity class looks like: @Entity(name="EMPLOYEE") public class Employee { @EmbeddedId private EmployeePK employeePK; //Other columns and their getters and setters //Getters and setters } Composite PK: @Embeddable public class EmployeePK implements Serializable { private long groupId; private long batchId; @GeneratedValue(strategy=GenerationType.AUTO) public long getBatchId() { return batchId; } public void setBatchId(long

How to autoincrement an Id in a composite primary key in Hibernate?

我与影子孤独终老i 提交于 2020-12-09 09:53:33
问题 I have a table with a composite primary key - groupId and batchId . Entity class looks like: @Entity(name="EMPLOYEE") public class Employee { @EmbeddedId private EmployeePK employeePK; //Other columns and their getters and setters //Getters and setters } Composite PK: @Embeddable public class EmployeePK implements Serializable { private long groupId; private long batchId; @GeneratedValue(strategy=GenerationType.AUTO) public long getBatchId() { return batchId; } public void setBatchId(long

How to INSERT using a SELECT in Hibernate

丶灬走出姿态 提交于 2020-12-08 08:47:18
问题 I need to implement the following request in hibernate: insert into my_table(....,max_column) values(...,(select max(id) from special_table where ....)) How to do that in hibernate, using annotations? special_table may be not a child or dependency of my_table, just a subselect. 回答1: You can use the INSERT INTO ... SELECT ... feature: int updateCount = session.createQuery(""" insert into MyEntity( ..., max_column ) select ..., max(id) from SpecialEntity """) .executeUpdate(); 来源: https:/

How to INSERT using a SELECT in Hibernate

ぐ巨炮叔叔 提交于 2020-12-08 08:46:52
问题 I need to implement the following request in hibernate: insert into my_table(....,max_column) values(...,(select max(id) from special_table where ....)) How to do that in hibernate, using annotations? special_table may be not a child or dependency of my_table, just a subselect. 回答1: You can use the INSERT INTO ... SELECT ... feature: int updateCount = session.createQuery(""" insert into MyEntity( ..., max_column ) select ..., max(id) from SpecialEntity """) .executeUpdate(); 来源: https:/

Hibernate restore soft-deleted entity

最后都变了- 提交于 2020-12-07 05:05:30
问题 I have an entity @Entity @Table(name = "[Usermaster]") @SQLDelete(sql = "UPDATE Usermaster SET isDeleted = 1") @Where(clause = "isDeleted = 0") public class User { //... } Now when I delete some Entity it actually will set deleteFlag = 1 How can I restore the entity? thanks 来源: https://stackoverflow.com/questions/24656518/hibernate-restore-soft-deleted-entity