Skip to main content

Posts

Showing posts with the label annotations

Why are annotations under Android such a performance issue (slow)?

I'm the lead author of ORMLite which uses Java annotations on classes to build database schemas. A big startup performance problem for our package turns out to be the calling of annotation methods under Android 1.6. I see the same behavior up through 3.0. We are seeing that the following simple annotation code is incredibly GC intensive and a real performance problem. 1000 calls to an annotation method takes almost a second on a fast box. The same code under Java can do 28 million (sic) calls in the same time. We have an annotation that has 25 methods in it and we'd like to do more than 50 of these a second. Does anyone know why this is happening and if there is any work around? There are certainly things that ORMLite can do in terms of caching this information but is there anything that we can do to "fix" annotations under Android? Thanks. public void testAndroidAnnotations() throws Exception { Field field = Foo.class.getDeclaredField("field");

How to auto insert Current DATE in SQL with Java / Hibernate

I need to add automatically the current date into my Database when I create a new OperantionBank. I'm using Hibernate. Thanks import java.io.Serializable; import java.sql.Date; import javax.persistence.*; import org.hibernate.annotations.Generated; import org.hibernate.annotations.GenerationTime; @Entity public class OperationBank implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String wordring; private Double amount; @Generated(GenerationTime.ALWAYS) @Temporal(javax.persistence.TemporalType.DATE) private Date dateoperation = new java.sql.Date(new java.util.Date().getTime()); @OneToOne private Account account;