10

I am using hibernate 4.1.9. My code is

@Transient
private String ldapIdTemp;

package is

import javax.persistence.Transient;

Still in hibernate query, it is not working and putting the attribute in the query.

part of query snippet (assetasset0_.ldapIdTemp as ldapIdTemp16_0_, )

I am not sure what I am doing wrong.

Arpit Aggarwal
  • 27,626
  • 16
  • 90
  • 108
romil gaurav
  • 1,121
  • 11
  • 23
  • 43

3 Answers3

14

Can you try creating setter and getter for the field and annotate the get method with @Transient, as follows:

private String ldapIdTemp;

 @Transient
 public String getLdapIdTemp() {
    return ldapIdTemp;
 }

 public void setLdapIdTemp(String ldapIdTemp) {
    this.ldapIdTemp = ldapIdTemp;
 }
Arpit Aggarwal
  • 27,626
  • 16
  • 90
  • 108
5

Much depends on how you "integrated" this field in your Entity or class hierarchy. Moreover, field vs. property-access could cause an issue for your setting. See this post for a detailed explanation.

In your case, I could imagine that you either:

  1. mixed field and property-access in your entity inheritance strategy
  2. use XML-based configuration for Hibernate in your application.

In both cases the JPA 2.0/2.1 specification clearly states in Section 2.3.1:

It is an error if a default access type cannot be determined and an access type is not explicitly specified by means of annotations or the XML descriptor. The behavior of applications that mix the placement of annotations on fields and properties within an entity hierarchy without explicitly specifying the Access annotation is undefined.

Please check that your persistent Entity classes have either field OR property-based annotations.

Community
  • 1
  • 1
MWiesner
  • 8,868
  • 11
  • 36
  • 70
2

Check the @Transient annotation fully qualified name. It can be from either, org.springframework.data.annotation.Transient or javax.persistence.Transient.

Try to use javax.persistence.Transient.

Saveendra Ekanayake
  • 3,153
  • 6
  • 34
  • 44
  • 1
    This was my problem. A previous coder had annotated a method using `java.beans.Transient` when the method didn't need the annotation because its name did not look like a getter or setter. His code ran, but when I used the same annotation on a new method that looked like a getter, the code failed. I switched to `javax.persistence.Transient` and the code ran. – Ron DeSantis Apr 28 '20 at 13:53