MyTetra Share
Делитесь знаниями!
postgresql to entity
Время создания: 30.11.2020 02:37
Раздел: INFO - Development - DATABASE - postgres
Запись: wwwlir/Tetra/master/base/1606675056kepm374fwv/text.html на raw.githubusercontent.com

import com.haulmont.cuba.core.global.*

import com.groupstp.rtneo.entity.*

import com.google.gson.Gson;

import com.google.gson.JsonObject;

import com.google.gson.JsonParser;

import com.haulmont.cuba.core.global.PersistenceHelper;

import com.haulmont.cuba.core.*


import com.haulmont.cuba.core.global.ViewRepository;

import com.haulmont.cuba.core.global.View;


DataManager dataManager = AppBeans.get(DataManager.NAME)

Persistence persistence= AppBeans.get(Persistence.NAME)



Transaction tr = persistence.createTransaction()


EntityManager em = persistence.getEntityManager();


String str = "with accruals as(\n" +

"select\n" +

"a.id as id, c.number_, a.document_number, a.\"period\", a.create_ts, row_number() over (partition by a.\"period\" order by a.create_ts desc) as num\n" +

"from\n" +

"rtneo_accrual a\n" +

"join rtneo_contract_position cp on\n" +

"a.contract_position_id = cp.id\n" +

"join rtneo_contragent_real_estate cre on\n" +

"cp.contragent_real_estate_id = cre.id\n" +

"join rtneo_contract c on cp.contract_id = c.id\n" +

"where\n" +

"a.delete_ts is null\n" +

"and cp.delete_ts is null\n" +

"and cre.delete_ts is null\n" +

"and cre.id = #cre::uuid\n" +//'0055bcc3-2c1a-484e-e537-3ebe1b9efa9d'

"order by a.\"period\"\n" +

")\n" +

"select accs.id from accruals accs where accs.num = 1"

Query query = em.createNativeQuery(str, Accrual.class);

query.setParameter("cre", "0055bcc3-2c1a-484e-e537-3ebe1b9efa9d");

List<Accrual> accruals = query.getResultList();

log.debug(accruals.size())

Так же в этом разделе:
 
MyTetra Share v.0.65
Яндекс индекс цитирования