# How to fetch a @Transient property from the database using JPA and Hibernate?

**URL:** <https://discourse.hibernate.org/t/how-to-fetch-a-transient-property-from-the-database-using-jpa-and-hibernate/1160>\
**Category:** Hibernate ORM\
**Created:** [August 2, 2018, 6:37pm UTC](https://discourse.hibernate.org/t/how-to-fetch-a-transient-property-from-the-database-using-jpa-and-hibernate/1160 "2018-08-02T18:37:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![artur1234](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@artur1234](https://discourse.hibernate.org/u/artur1234)\
**Post date:** [August 2, 2018, 6:37pm UTC](https://discourse.hibernate.org/t/how-to-fetch-a-transient-property-from-the-database-using-jpa-and-hibernate/1160/1 "2018-08-02T18:37:25Z")

</div>

Example:

```
List<Subdivision> subdivision = session.createQuery(sql).list();

```

As far as I know in the Subdivision class, there must be a default constructor - it is there.

I have 3 fields in the Subdivision class:

1. 

```
 @Id
 @GeneratedValue (strategy = GenerationType.IDENTITY)
 private int idSubdivision;

```

2. 

```
@Column(name = "nameSubdivision", unique = true)
private String nameSubdivision; 

```

3. 

```
 @Transient 
 VBox vbox; (javafx.scene.layout.VBox)

```

The first two fields are filled in using session.createQuery (sql) .list ();

But I need the third field of vbox to be filled in the Subdivision class. It is filled in from me based on the value of the nameSubdivision field. In the database, the vbox field is of course not present, so it does not fill out.

Of course I can go through the generated List subdivision and fill in this field.

But I wanted to do everything at once. Can I access session.createQuery (sql) .list () - and override it so that it takes into account my field

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [August 7, 2018, 9:08am UTC](https://discourse.hibernate.org/t/how-to-fetch-a-transient-property-from-the-database-using-jpa-and-hibernate/1160/2 "2018-08-07T09:08:07Z")

</div>

You have multiple options:

1. You can use the `@Generated` annotation as explained in [this article](https://vladmihalcea.com/how-to-map-calculated-properties-with-hibernate-generated-annotation/).
2. You can use the `@Formula` annotation as explained in [this article](https://vladmihalcea.com/how-to-map-calculated-properties-with-jpa-and-hibernate-formula-annotation/).
