Define a variable in an Entity class that is not a column

In my WAS application, I have a requirement to define a variable (String) in the Entity class, which maps to a table. Therefore, the fields associated with the table are annotated as @Column (name = "column_name") I have a requirement to add a new field / variable to this Entity class, which is not a column in the table. If I declare this a normal field, JPA will also convert this field to SQL. This causes SQL error -206 (as expected).

How can I declare this field? Is there an annotation that I can use to say its custom variable and not associated with any of the columns in the table defined by this Entity?

Example:

@Entity
@Table(name = "TABLE_1")
@NamedQueries(
 {
@NamedQuery(name = "abc:findTableContent", query = "SELECT u FROM TABLE_1 u WHERE u.Id = :iD"),
 })
public class TableEntity1 implements Serializable
{
    @Id
    @Column(name = "TABLE1_ID")
    private Long iD;

    @Column(name = "DESC")
    private String desc;


    private String error;    


}

, namedquery, "SELECT t0.iD, t0.desc, t0.error FROM TABLE_1 u WHERE u.iD =?"

? !

+4
1

. @javax.persistence.Transient

+8

Source: https://habr.com/ru/post/1530516/


All Articles