0

I am developing an application that has 3 servers to deploy: dev, home prod. In the database, we have some views from others databases. In development, we have control of our DB and we can create a view and insert some data to test. In dev and production, we do not control DB. So, some views are not created yet.

I have a to like this

public class myDTO {
  Long id;
  Double quantity;
  Map<String, Double> loadTypes; // come from view
}

I have a method findAll in a @Transactional class that get loadTypes from DB, but as my class is @Transactional when I try to access the Table I got error 500 and myDTO is not returned, I want to return the rest of the DTO even when view that I need to access to get loadTypes does not exist. Is there a way that I could do that?

I am getting this error

org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:526)
M. Deinum
  • 115,695
  • 22
  • 220
  • 224
Rafael Andrade
  • 495
  • 1
  • 5
  • 22
  • Even if you found a way to do that, it would be a horrible thing to do. Your problem is that there's a missing view that you're trying to use. Don't do that. Why would your code try to use resources that don't exist? – Kayaman Aug 02 '18 at 11:48
  • @Kayaman I know, its really strangeBut as `id` and `quantity` should come up on screen even without loadTypes, should I separete the DTO? Our leader want to return the data even tho the view does not exist yet – Rafael Andrade Aug 02 '18 at 11:54
  • The DTO isn't your problem, your entity is. If you're writing code that works differently depending on the database schema (which is a really bad idea to begin with), then you'll have to perform custom loading and other things. Hibernate assumes that you know the database you're working with, none of that "load this if it's there" thing you're going for. – Kayaman Aug 02 '18 at 11:57
  • The view will eventually be created @Kayaman. But take some time, we need to open an ticket, the client IT team will update DB. The code is working fine, but our leader do not want see an 500 response because of that. I am trying to do something only until this view is not created on hom and production. – Rafael Andrade Aug 02 '18 at 13:20
  • Well I hope you understand that you're doing something horrible. Having a database in an undefined state is not okay, no matter what the "leader" says. You'll probably have to work with native queries and do all sorts of partial loading. The code in your example doesn't show your entity, how you load it or anything else relevant so it's hard to solve your immediate problem. I recommend reading a lot of material on Hibernate, as you don't seem to be very experienced with it. – Kayaman Aug 03 '18 at 05:36

0 Answers0