4

I have Settlement entity

@Entity
@Table(name = "settlement")
public class Settlement {

    @ManyToOne
    @JoinColumn(name = "subscription_x_product_id")
    private ProductSubscription productSubscription;

which related to ProductSubscription entity

@Entity
@Table(name = "subscriptionproduct")
public class ProductSubscription {
    @ManyToOne
    @JoinColumn(name = "product_id")
    private Product product;

which related to Product entity

@Entity
public class Product {
    @Transient
    private String enabled;

in Product entity i have field enabled which annotated with @org.springframework.data.annotation.Transient. also I have Repository

public interface SettlementRepository extends JpaRepository<Settlement, Integer>

when I call SettlementRepository.findAll(); it give exception Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'enabled'.

How can I ignore the enabled field from being loaded from the DB ?

Melad Basilius
  • 3,847
  • 10
  • 44
  • 81

1 Answers1

13

I found the solution, the problem was in Annotation @org.springframework.data.annotation.Transient once I changed to @javax.persistence.Transient it worked fine.

Melad Basilius
  • 3,847
  • 10
  • 44
  • 81
  • 2
    I've the same problem but I was using `@Transient` from `@javax.persistence.Transient` from the beginning but still no success. I save the entity and call the get method on the returned object and the value was persisted. Have you found something else? Thanks. – fabioresner Jul 27 '17 at 17:29
  • 2
    For further readers, the annotation is actually working, but as I'm using it in a `@Transactional` Test, spring repository seems to be not updating the Object (the object saved and the returned from the repository have the same Object Id). So the field was not being written in the database but the Repository is still returning it, even if I call the findOne and assigns it to a new variable. Still don't know how to fix it. – fabioresner Jul 27 '17 at 18:22
  • @fabioresner something error in your enitty (for me, I had wrong \@UniqueConstraint name) and you must defined query in xml file like this: <![CDATA[SELECT * from tableName where id = :myId]]> – nobjta_9x_tq Jan 30 '18 at 10:33
  • 1
    @fabioresner check this answer: https://stackoverflow.com/a/42753469/5695421 – dk7 Dec 22 '19 at 20:41