tags:

views:

51

answers:

3

briefly, can someone tell me what an annotation is in hiberate? (java)

is it a way to quickly map entities to tables?

A: 

Yes, Hibernate annotations are used on domain classes, instead of using mapping files (hibernate.cfg.xml, etc.). I guess you can google about details. Briefly, it is a more convenient way to define your mappings and their attributes.

Bozho
A: 

Its way more than that. In hibernate they are used to tell the tools that process your code the meaning of the parts of your code. So

 @Entity
 public class MyClass{}

will be processed (that is the code itself will be read) and the @Entity annotation indicates that the MyCLass class is an Entity - represents real world data.

A similar thing can be achieved with xml files but that would required managing multiple files.

So in a way it allows you to specify meta data about your code.

Vincent Ramdhanie
so in .net we use attributes right? like []
mrblah
Thats right. They provide a similar function and they both support custom attributes or annotations.
Vincent Ramdhanie
A: 

Basically your annotations are your analogous of the xml config that's all there is to it, so therefore the annotations equivalent of

<property name="description" column="descriptive_text" />

is

@Column(name="descriptive_text")
private String description;

Keep in mind that @Column is the JPA standard (@javax.persistence.Column) of which Hibernate is an implementation. There are, of course, Hibernate specific annotations like @org.hiberanate.annotations.Immutable which specifies that an entity or collection are immutable. Further info here.

non sequitor