Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to maintain consistency of column name (Java + jsp) using Hibernate?
    primarykey
    data
    text
    <p>I have this POJO:</p> <pre class="lang-java prettyprint-override"><code>Place.class: @Entity @Table(name="place") public class Place { @Id @Column(name="idPlace") private Integer id; @Column(name="descr") private String description; // getter &amp; setter } </code></pre> <p>Into the Dao implementation if I want to filter by place description (for example) I add a Restriction:</p> <pre class="lang-java prettyprint-override"><code>getSession().createCriteria(Place.class).add(Restrictions.like("description", "description-filter-value")); </code></pre> <p>Moreover if into the view (example: create.jsp) I want to refer to the description column I write an input like this:</p> <pre><code>&lt;input type="text" name="description" /&gt; </code></pre> <p>If in the future I need (for various reasons) to <strong>rename</strong> the field <code>description</code> I should be find all the references into the project to the labels "description", both Java and jsp, and rename them; too ugly and boring.</p> <p>There is a way to write this code in a <em>consistent</em> way?</p> <p>I think to add a static field into <code>Place.java</code>:</p> <pre class="lang-java prettyprint-override"><code>public static final String DESCRIPTION = "description"; </code></pre> <p>and change the previous code to:</p> <pre class="lang-java prettyprint-override"><code>getSession().createCriteria(Place.class).add(Restrictions.like(Place.DESCRIPTION, "description-filter-value")); </code></pre> <p>and</p> <pre><code>&lt;input type="text" name="&lt;%=Place.DESCRIPTION%&gt;" /&gt; </code></pre> <p>but I would know if exists a batter way to do that.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload