hibernate

Spring JPA + dynamically switch the datasource between schemas in postgresql

依然范特西╮ 提交于 2021-02-08 03:05:51
问题 I have to modify design of the existing application according to following manner, According to above design each project contains it's own schema and that mapping table (project_schema_table) is under main schema. All schemas are under one Postgresql database and in future users will create another new schemas (on demand) for their new projects. Before displaying login window I have to list all existing projects and once user select his project I have to direct to that project with relevant

Check if object is referenced to prevent soft-deleting without modifying database

末鹿安然 提交于 2021-02-08 02:15:20
问题 As you can see I am using soft/logical deletion on my system: My entities: @Where(clause = "deleted='false'") public class Person { //... } My services: @Override public ServiceResponse DeletePerson (Person entity) { ServiceResponse sr = new ServiceResponse<>(); try { sr = ValidateDeletePerson(entity); //Business logic treatment if (sr.hasError()) return sr; Person dbEntity = GetPerson(entity.getPersonID()); dbEntity.setDeleted(true); _repository.save(dbEntity); } catch (Exception ex) { sr

Check if object is referenced to prevent soft-deleting without modifying database

ぐ巨炮叔叔 提交于 2021-02-08 02:12:17
问题 As you can see I am using soft/logical deletion on my system: My entities: @Where(clause = "deleted='false'") public class Person { //... } My services: @Override public ServiceResponse DeletePerson (Person entity) { ServiceResponse sr = new ServiceResponse<>(); try { sr = ValidateDeletePerson(entity); //Business logic treatment if (sr.hasError()) return sr; Person dbEntity = GetPerson(entity.getPersonID()); dbEntity.setDeleted(true); _repository.save(dbEntity); } catch (Exception ex) { sr

difference between filters and criteria in hibernate

北城余情 提交于 2021-02-07 20:53:40
问题 What is the difference between filters and criteria in hibernate? criteria is used to filter the records by greater than,less than or equal etc.It is kind of filters.Can somebody show me what is difference by simple example 回答1: Short answer: A filter allows you to define a restriction clause similar to the existing "where" attribute available on the class and various collection elements. These filter conditions, however, can be parameterized. The application can then decide at runtime

Hibernate criteria accepting %% value

十年热恋 提交于 2021-02-07 20:48:40
问题 I am using the below Hibernate code to filter workFlowName . crt.add(Restrictions.like("workFlowName", workFlow, MatchMode.ANYWHERE)); // crt is the criteria The problem is when I pass the value to workFlow from web (TextBox).it fetching the value correctly (I am passing sym in text box if fetch 10 records.if i pass the same value like %sym% again it is fetching same record). Whether the criteria will omit when it see %% as argument? 回答1: Hibernate does not escape special chars in like (e.g.

Problem with Entity update with jpa/hibernate

守給你的承諾、 提交于 2021-02-07 20:44:36
问题 I have this entity class, called "Pagina" and I want to update the entry in the database based on the changes made to the entity. This isn't working. I get no errors, but the db is not changed. @Entity @Table(name = "PAGINA") @NamedQueries({@NamedQuery(name = "Pagina.findAll", query = "SELECT p FROM Pagina p"), @NamedQuery(name = "Pagina.findHashByURL", query= "SELECT p.chash FROM Pagina p WHERE p.url = :url"), @NamedQuery(name = "Pagina.findTimestampByURL", query= "SELECT p.timestamp FROM

Problem with Entity update with jpa/hibernate

寵の児 提交于 2021-02-07 20:43:27
问题 I have this entity class, called "Pagina" and I want to update the entry in the database based on the changes made to the entity. This isn't working. I get no errors, but the db is not changed. @Entity @Table(name = "PAGINA") @NamedQueries({@NamedQuery(name = "Pagina.findAll", query = "SELECT p FROM Pagina p"), @NamedQuery(name = "Pagina.findHashByURL", query= "SELECT p.chash FROM Pagina p WHERE p.url = :url"), @NamedQuery(name = "Pagina.findTimestampByURL", query= "SELECT p.timestamp FROM

Spring transaction and rollback on multiple tables

走远了吗. 提交于 2021-02-07 19:50:39
问题 I'm struggling on transaction magement using DAO. The scenario is to create new quote that contains a list of quote_line and a customer. If the customer doesn't exist, it will insert it in the table customer. My code is architectures as follow : @Entity @Table(name = "quote") public class Quote { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; //....properties @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "customer_id", nullable = true) private Customer customer;

the hibernate-envers with liquibase

[亡魂溺海] 提交于 2021-02-07 19:22:35
问题 My question can be trival, but documentation for hibernate-envers say I need just 2 steps to make hibernate envers work: the hibernate-envers jar on the classpath, an @Audited annotation on the entity. First of all I added: <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-envers</artifactId> <version>5.2.12.Final</version> </dependency> Second I added @Audited annotation above my entity: @Entity @Audited @Table(name = "users") public class User {...} After those 2 steps I

hibernate @Entity on inner class only (top level class is not an @Entity)

夙愿已清 提交于 2021-02-07 18:47:54
问题 I would like to persist inner class into database. But it dosnt work. Is there possibilty to do that? Or should i put that inner class into new plain file? Now I am getting an error [IllegalArgumentException: Unknown entity: models.foo$bar] My class file: package models; public class foo { @Required public String report; @Required public String reportType; @Entity public static class bar{ @Required public int year; @Required public int month; public void toDataBase() { JPA.em().persist(this);