Reputation: 1517
I am learning hibernate and my instructor told that type attribute in <id>
and <property>
tag is optional but if the field is of type integer we should specify the type attribute. While creating the mapping I skipped the type attribute even my id was integer but my program run successfully.
<hibernate-mapping>
<class name="myPack.Trainer">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
<set name="batches" table="Batches" cascade="all">
<key column="trainerId"/>
<one-to-many class="myPack.Batch"/>
</set>
</class>
<class name="myPack.Batch">
<id name="id">
<generator class="native"/>
</id>
<property name="slot"/>
<property name="topic"/>
</class>
</hibernate-mapping>
So is there any issue if I don't use type attribute even if my id or property field is integer.
Upvotes: 0
Views: 185
Reputation: 354
Yes Type tag is optional.
you can use it to mention the appropriate hibernate dataType for your java dataType, so that hibernate will use correct dataType for ur database column.
The name of a Hibernate basic type (eg. integer, string, character, date, timestamp, float, binary, serializable, object, blob).
The name of a Java class with a default basic type (eg. int, float, char, java.lang.String, java.util.Date, java.lang.Integer).
Upvotes: 1