Reputation: 415
I know its weird but I am having that problem. I have one simple pojo class and using struts+hibernate, I am updating a oracle table through JPA. the only tricky thing I am using is oracle sequence which called before every insert query.
But when I use hbm.xml file it's giving result very fast compare to annotation mapping. I want to switch to annotation, can anyone have any idea what can be the cause.
hbm.xml file is something like that
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class name="com.myproject.VersionSequence"
table="Version_Sequence"
dynamic-update="true">
<meta attribute="sync-DAO">false</meta>
<id name="id" column="ID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">Oracle_Sequence</param>
</generator>
</id>
<property name="version" column="VERSION" type="java.lang.Long" not-null="true" />
.
.
.
.
</class>
</hibernate-mapping>
Annotation correspond file for above xml file
@Entity
@Table(name="Version_Sequence")
public class VersionSequence implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator = "Oracle_Sequence")
@GenericGenerator(name = "Oracle_Sequence",
strategy = "sequence-identity",
parameters = { @Parameter(name = "sequence", value = "Oracle_Sequence") })
@Column(name = "ID")
private Long id;
@Column(name = "VERSION")
private Long version;
.
.
.
// getter/seeters
}
Upvotes: 0
Views: 466
Reputation: 2568
First we need to understand the working of annotation.
Example -
The Definition of @GenericGenerator
The applied annotation is @Retention(RUNTIME) which means annotation should be available for reflection at run time.
Annotation uses reflection and reflection is slow.
Why reflection is slow ?
Every step is validated when you take in reflection.
For example, when you invoke a method, it needs to check whether the target is actually an instance of the declarer of the method, whether you've got the right number of arguments, whether each argument is of the right type, etc.
Annotations are based on reflection.
Upvotes: 1