0
I have Class Customer ,User , Customer has property manager of user class 

Class Customer { 

/** The manager. */ 
    @ManyToOne(optional = false, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE}) 
    @JoinColumn(name = "MANAGER") 
    @JsonSerialize(using = EntitySerializer.class) 
    @JsonDeserialize(using = UserDeserializer.class) 
    private User manager; 
} 
------------------------------------- 
Class User { 
    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO, generator = User.TABLE_NAME + "_SEQUENCE") 
    @SequenceGenerator(name = User.TABLE_NAME + "_SEQUENCE", sequenceName = User.TABLE_NAME + "_SEQ") 
    @Column(name = FIELD_ID, nullable = false) 
    @SuppressWarnings("PMD.ShortVariable") 
    private Integer id; 

@Override 
public Integer getId() { 
     return id; 
    } 

@Override 
    public void setId(final Integer newId) { 
     //System.out.println("setID"); 
     id = newId; 
    } 
} 

Теперь, когда я пытаюсь создать критерииОшибка: - org.hibernate.PropertyAccessException:. Не может получить значение поля с помощью отражения добытчика

окончательные критерии Критерии = getSession() createCriteria (Customer.class) ; criteria.add (Restrictions.ilike ("Менеджер", "%" + SEARCHTERM + "%"))

Это бросали ошибки: - org.hibernate.PropertyAccessException: не мог получить значение поля за счет отражения от геттер ком .User.id

Вызванный: java.lang.IllegalArgumentException: Невозможно установить java.lang.Integer поле com.User.id к java.lang.String

** поле Id является целым числом **

ответ

0

Не могли бы вы изменить следующее:

final Criteria criteria = getSession().createCriteria(Customer.class); criteria.add(Restrictions.ilike("manager", "%"+searchTerm+"%")) 

следующие:

final Criteria criteria = getSession().createCriteria(Customer.class); criteria.add(Restrictions.ilike("manager.name", "%"+searchTerm+"%")) 

LIKE статьи применим только к текстовому колонку.

+0

Но в ситуации, мне нужно фильтровать мое состояние WRT к ид ... т.е. manger.id. Любой способ архивирования –

-1

Вы использовали эту аннотацию ошибки удалить

@Table(name="user_training") 
@Entity 
public class UserTraining { 

    @Id 
    @GeneratedValue 
    @Column(name="id") 
    private int id; 

    //Generate getter setter of id 
/* 
    @Column(name="user_id") 
    private int userId; 

    */ 


    @JsonIgnore 
    @ManyToOne(cascade = {CascadeType.ALL}) 
    @JoinColumn(name = "user_id") 
    private UserProfile userProfile; 


    public UserProfile getUserProfile() { 
     return userProfile; 
    } 


    public void setUserProfile(UserProfile userProfile) { 
     this.userProfile = userProfile; 
    } 

    @OneToOne 
    @JoinColumn(name = "training_id") 
    private Training training; 

    @Column(name="view_count") 
    private int viewCount; 

    public int getId() { 
     return id; 
    } 

    public void setId(int id) { 
     this.id = id; 
    } 


    public Training getTraining() { 
     return training; 
    } 

    public void setTraining(Training training) { 
     this.training = training; 
    } 

    public int getViewCount() { 
     return viewCount; 
    } 

    public void setViewCount(int viewCount) { 
     this.viewCount = viewCount; 
    } 

} 
+0

Как это сделать? – Sergii

+0

my this error remove to below anotation @JsonIgnore \t @ManyToOne (cascade = {CascadeType.ALL}) –

0

этот код используется

return this.sessionFactory.getCurrentSession() 
          .createCriteria(UserTraining.class) 
          .add(Restrictions.eq("userProfile.userId", userId)) 
          .list();