0

I am going through various hibernate methods like

persist()
save()
update()
merge()

All talk about differences in one returning identifier other returning not.

Can anyone tell me what is an identifier they are talking about?

What is the use of that?

I am sure it's not the Primary Key.

underdog
  • 4,447
  • 9
  • 44
  • 89
  • possible duplicate of [What are the differences between the different saving methods in Hibernate?](http://stackoverflow.com/questions/161224/what-are-the-differences-between-the-different-saving-methods-in-hibernate) – OldProgrammer Jan 06 '14 at 19:07
  • No it's a completely different question; I am asking what is an identifier not the differences between hibernate methods. – underdog Jan 06 '14 at 19:09
  • Have you read the documentation? You do not provide any references to "All talk about differences..." Please be specific. – OldProgrammer Jan 06 '14 at 19:11

1 Answers1

1

Identifier refers to the attribute name of <id> element in .hbm file or @Id annotation.

Mark the identifier property with @Id.

@Entity
public class Person {
   @Id Integer getId() { ... }
   ...
}  

In hbm.xml, use the <id> element which defines the mapping from that property to the primary key column.

<id
    name="propertyName"                                
    type="typename"                                    
    column="column_name"                               
    unsaved-value="null|any|none|undefined|id_value"   
    access="field|property|ClassName">                 
    node="element-name|@attribute-name|element/@attribute|."

    <generator class="generatorClass"/>
</id>  
  • name (optional): the name of the identifier property.
  • type (optional): a name that indicates the Hibernate type.
  • column (optional - defaults to the property name): the name of the primary key column.
  • unsaved-value (optional - defaults to a "sensible" value): an identifier property value that indicates an instance is newly instantiated (unsaved), distinguishing it from detached instances that were saved or loaded in a previous session.
  • access (optional - defaults to property): the strategy Hibernate should use for accessing the property value.

Related link

Aniket Kulkarni
  • 12,825
  • 9
  • 67
  • 90