So i am using Hibernate, and i got this an entity called personAddress, this is an entity that exists on the database, since i am using microservices i use namedQuerys to do the joins, since there are some entities i need to join but i dont have, this is my native query in my hbm:
select address.*, cit.description cityName, sta.description stateName, ctry.description_iso_common countryName from PERSON_ADDRESS address
inner join APP_CITIES cit on cit.id =address.city_id
inner join APP_STATES sta on sta.id= address.state_id
inner join APP_COUNTRY ctry on ctry.id = address.country_id
and address.person_id = :param
thing is , the cityName, stateName and countryName aren't on the database object since they come from a relation , so in my entity i have them as @Transient, but still , on persist , it tries to persist those columns so it returns persistance error (com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'cityName') if i set the getter of the class as @Transient, it doesnt give the persistance error but then the query doesn't print the city. This is my findByPersonIs function in my repository:
public List<PersonAddress> findByPersonIs(String iso,String personId, int offset, int limit){
Query<PersonAddress> namedQuery = null;
namedQuery = sessionFactory.getCurrentSession().createNamedQuery("findByPersonIs", PersonAddress.class);
namedQuery.setParameter("param", "%".concat(personId).concat("%").toLowerCase());
// namedQuery.setParameter("codeIso", "%".concat(iso).concat("%").toLowerCase());
namedQuery.setParameter("param", personId);
//namedQuery.setParameter("codeIso", iso);
namedQuery.setMaxResults(limit).setFirstResult(offset);
return namedQuery.getResultList();
}
Would appreciate help to solve this issue since i cannot bring the missing tables to the shared (DDD) nor doesn't allow me to retrieve the query into a DTO (not sure why)
I was expecting that as an entity has a @Transient field this doesn't go persisted, but somehow still would like to retrieve this value.