Reputation: 42967
I am working on a Java web application that I think use Hibernate and I am not so into Hibernate so I have the following doubt:
I have a model class named ReaDichiarazioneIntento that map a database table named REA_DICHIARAZIONE_INTENTO, something like this:
@javax.persistence.IdClass(it.enel.wearea.entity.ReaDichiarazioneIntentoPK.class)
@javax.persistence.Table(name = "REA_DICHIARAZIONE_INTENTO", schema = "EDIWEA")
@Entity
public class ReaDichiarazioneIntento implements Cloneable {
private Integer idDichiarazione;
@javax.persistence.Column(name = "ID_DICHIARAZIONE")
@Id
public Integer getIdDichiarazione() {
return idDichiarazione;
}
public void setIdDichiarazione(Integer idDichiarazione) {
this.idDichiarazione = idDichiarazione;
}
private Integer idCliente;
@javax.persistence.Column(name = "ID_CLIENTE")
@Basic
public Integer getIdCliente() {
return idCliente;
}
public void setIdCliente(Integer idCliente) {
this.idCliente = idCliente;
}
...................................................................
...................................................................
...................................................................
SOME OTHER FIELDS AND RELATED GETTER AND SETTER METHODS
...................................................................
...................................................................
...................................................................
}
Ok I have some doubts about this class. My doubt are:
1) Is it using Hibernate for mapping the class to the database table? Or what? I know that to map a database table to a class I have to do something like:
@Entity
@Table(name = "REA_DICHIARAZIONE_INTENTO")
Why in this project do:
@javax.persistence.IdClass(it.enel.wearea.entity.ReaDichiarazioneIntentoPK.class)
@javax.persistence.Table(name = "REA_DICHIARAZIONE_INTENTO", schema = "EDIWEA")
@Entity
What is the difference between the @Table(name = "REA_DICHIARAZIONE_INTENTO") annotation and the @javax.persistence.Table(name = "REA_DICHIARAZIONE_INTENTO", schema = "EDIWEA") annotation (used in my project)?
2) The second doubt is related to this annotation:
@javax.persistence.IdClass(it.enel.wearea.entity.ReaDichiarazioneIntentoPK.class)
What exactly means?
3) The last doubt is related to the mapping between a class field to a table column on the DB. Why is it done only on the getter method and not directly on the field name?
Tnx
Upvotes: 0
Views: 118
Reputation: 24433
@Table
annotation but it is used for additional information supplied by JPA'a @Table
annotation@IdClass
means that the complex primary key is used for this entitySpecifies a composite primary key class that is mapped to multiple fields or properties of the entity.
@Id
mapping dictates what is valid, meaning if you put @Id
on field then you must put all other mappings on fields also, and vice versa.Upvotes: 2
Reputation: 11267
This is using JPA, looks like, not hibernate. Here is the difference according to SO and here is another link
Upvotes: 1