jpa

Wildfly - set datasource password at runtime

我怕爱的太早我们不能终老 提交于 2021-02-08 03:45:57
问题 I am developing a server application using Jboss wildfly 8.1 and JPA Hibernate. The problem is, that the JPA datasource creditials have to be loaded at runtime (password). When the server starts, it connects to an encrypted storage where it retrieves password to real database. After that, it should establish connection to the real database. I tried several things already: Lookup the datasource through JNDI and rebind it with actual DS. Lookup the entityManagerFactory through JNDI and rebind

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

Cast Entity inside a query

放肆的年华 提交于 2021-02-07 20:56:22
问题 I'm looking for a way to cast an entity inside a jpql query. Example: @Entity class Topic { @OneToMany List<AbstractMessage> messages; } @Entity @Inheritance(strategy = InheritanceType.JOINED) abstract class AbstractMessage { String content; } @Entity class MessageType1 extends AbstractMessage { String att1; } @Entity class MessageType2 extends AbstractMessage { Integer att2; } I'm trying to collect all Topic where one or more of its messages have the type MessageType2 and have att2 = 1. Here

Cast Entity inside a query

孤者浪人 提交于 2021-02-07 20:55:26
问题 I'm looking for a way to cast an entity inside a jpql query. Example: @Entity class Topic { @OneToMany List<AbstractMessage> messages; } @Entity @Inheritance(strategy = InheritanceType.JOINED) abstract class AbstractMessage { String content; } @Entity class MessageType1 extends AbstractMessage { String att1; } @Entity class MessageType2 extends AbstractMessage { Integer att2; } I'm trying to collect all Topic where one or more of its messages have the type MessageType2 and have att2 = 1. Here

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

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

Skip child to fetching of parent - JPA

僤鯓⒐⒋嵵緔 提交于 2021-02-07 19:01:49
问题 I am facing an issue where the data is getting fechted recursively. I wanted to avoid the child to fetch the parent data. Which is causing a recursive issue. I have mentioned the code below Pojo Structure class Parent { .. @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY) private List<Child> childs; .. } class Child { .. @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "parentId") private Parent parent; .. } Fetching the data like this ` em = EMF.get().createEntityManager(); Query