Dear all hibernate developers,
The following hibernate hbm2java class I am using in my application. I need the name field while I am getting the data from database by join two tables. (This data I have to display in a grid in UI.)
However I am getting problem when I am trying insert a record into rxJournal table.
The error is:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'name' in 'field list'
I want to ignore/skip the ‘name’ filed While insert or update a record by using hibernate.
Following is my HBM class:
@Entity
@Table(name = "rxJournal", catalog = "Company")
public class RxJournalBean implements java.io.Serializable {
private Integer rxJournalId;
private String entryMemo;
private String name;
....
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "rxJournalID", unique = true, nullable = false)
public Integer getRxJournalId() {return this.rxJournalId;}
public void setRxJournalId(Integer rxJournalId) {this.rxJournalId = rxJournalId;}
@Column(name = "EntryMemo")
public String getEntryMemo() {return this.entryMemo;}
public void setEntryMemo(String entryMemo) {this.entryMemo = entryMemo;}
public String getName() {return name;}
public void setName(String name) {this.name = name;}
}
I can create another bean by removing name field alone, however I don’t want to use redundant code. Kindly give me any suggestions.
Please ignore if I am asking any repeated question and point me to right solution.
Thanks in advance.
If I understand correctly, you would like to have a name property in your entity, but you would like this property to be non-persistent (i.e. completely ignored by Hibernate).
If so, that’s what @Transient is for:
The name property will of course be null for every instance loaded by Hibernate from the database. It will only have a value if you assign one.