I am using Hibernate to map with MySQL
I have an entity class in which I have the methods mapped with columns in MySQL
The question is, if its possible that I do not map some of the method in that class with any column in SQL, as if i try not to map one of my method in entity class, it gives exception.
Here is the code snippet
@Column(name="skills")
public String getSkills() {
return skills;
}
public int getRowCount() {
return rowCount;
}
In this above code I have assigned getSkills with Column skills in SQL, but I do not want to assign getRowCount()
with any column in MySQL.
How could i achieve that (as in this above situation its giving exception, rowCount
is unknown)?
Introduction. When persisting Java objects into database records using an Object-Relational Mapping (ORM) framework, we often want to ignore certain fields. If the framework is compliant with the Java Persistence API (JPA), we can add the @Transient annotation to these fields.
Every non static non transient property (field or method depending on the access type) of an entity is considered persistent , unless you annotate it as @Transient . So you can use @Transient annotation on the property you do not wish to create a column for in database.
To ignore a field, annotate it with @Transient so it will not be mapped by hibernate.
If no @Table is defined the default values are used: the unqualified class name of the entity. For example if you have: @Entity public class MyTest{ ... Your table will have the name my_test in your database.
Use the @Transient
annotation:
This annotation specifies that the property or field is not persistent. It is used to annotate a property or field of an entity class, mapped superclass, or embeddable class.
i.e.
@Column(name="skills")
public String getSkills() {
return skills;
}
@Transient
public int getRowCount() {
return rowCount;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With