JPA - wrong number of column. should be 2 - java

A Foreign key refering br.com.copagaz.inova.mobile.persistencia.entidade.viagem.nf.NFeProtocolo from br.com.copagaz.inova.mobile.persistencia.entidade.viagem.nf.NfCabeca has the wrong number of column. should be 2
My problem is in one column reference, if i remove #ManyToOne and #JoinColumn(name = "protocolo"), the system works but the selects does not.
i tried to use hibernate.hbm2ddl.auto to auto create the FKs but with no success.
I think the nfe_operacao use a composed PK, and nf_cabeca reference's ii, but did not work.
Any one could help?
#Entity
#Table(name = "nf_cabeca", schema = "mobile", uniqueConstraints =
{#UniqueConstraint(columnNames =
{"NUMERO_FILIAL","serie_nota","numero_nota"})})
public class NfCabeca implements java.io.Serializable {
private static final long serialVersionUID = -921687831233770627L;
#Id
#SequenceGenerator(name = "nf_cabeca_sequencial_seq", sequenceName = "nf_cabeca_sequencial_seq", schema = "mobile", allocationSize = 1, initialValue = 1)
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "nf_cabeca_sequencial_seq")
#Column(name = "sequencial", insertable = false, updatable = false)
private long sequencial;
#Temporal(TemporalType.TIMESTAMP)
#Column(name = "data_hora", nullable = false, length = 29)
private Date dataHora;
#Column(name = "valor_total", nullable = false, precision = 17, scale = 17)
private Double valorTotal;
#Column(name = "cancelada")
private Integer cancelada;
#Temporal(TemporalType.DATE)
#Column(name = "data_vencimento", length = 13)
private Date dataVencimento;
#Column(name = "boleto", length = 17)
private String boleto;
#ManyToOne
#JoinColumn(name = "protocolo")
private NFeProtocolo protocolo;
#Column(name = "chave")
private String chave;
#Column(name = "status_nf")
private Integer statusNf;
#Column(name = "status_danfe")
private Integer statusDanfe;
#Column(name = "modelo", length = 3)
private String modelo;
#Column(name = "reconciliada")
private boolean reconciliada = false;
#OneToMany(mappedBy = "nfCabeca", cascade = CascadeType.MERGE)
private List<NfObservacao> nfObservacao;
#OneToMany(mappedBy = "nfCabeca", cascade = CascadeType.ALL)
private List<NfItens> nfItens;
#OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
#JoinColumn(name = "nf_cabeca")
private List<NFeProtocolo> protocolos = new ArrayList<NFeProtocolo>();
}
This references this table:
#Entity
#IdClass(NFeProtocoloId.class)
#Table(name = "nfe_protocolo", schema = "mobile")
public class NFeProtocolo implements Serializable {
private static final long serialVersionUID = 2092981840170296102L;
#Id
#Column(name = "nf_cabeca", length = 100, insertable = false, updatable = false)
private long nf_cabeca_id;
#Id
#Column(name = "protocolo", length = 100)
private String protocolo;
#Column(name = "operacao", length = 15, nullable = false)
#Enumerated(EnumType.STRING)
private NFeProtocoloOperacao operacao;
#Temporal(TemporalType.TIMESTAMP)
#Column(name = "data_hora", length = 29, nullable = false)
private Date dataHora;
#Column(name = "status", length = 10)
private String status;
}

I think the problem is that your #ManyToOne mapping is not correctly declared. As the the entity NFeProtocolo has a composite primary key, you should use #JoinColumns annotation that consists of an array of #JoinColumn annotations:
#ManyToOne
#JoinColumns({#JoinColumn(name = "nf_cabeca_id", referncedColumnName="nf_cabeca_id"),
#JoinColumn(name= "protocolo", referencedColumnName="protocolo")})
private NFeProtocolo protocolo;
You can choose an appropriate name as a foreign key column name.

A Foreign key refering br.com.copagaz.inova.mobile.persistencia.entidade.viagem.nf.NFeProtocolo from br.com.copagaz.inova.mobile.persistencia.entidade.viagem.nf.NfCabeca has the wrong number of column. should be 2
Your problem is simple: Your Entity NFeProtocolo has a composite Id with two columns:
public class NFeProtocolo implements Serializable {
#Id
#Column(name = "nf_cabeca", length = 100, insertable = false, updatable = false)
private long nf_cabeca_id;
#Id
#Column(name = "protocolo", length = 100)
private String protocolo;
But your class NfCabeca is referencing it through only one column:
public class NfCabeca implements java.io.Serializable {
#ManyToOne
#JoinColumn(name = "protocolo")
private NFeProtocolo protocolo;
The solution:
A composite primary key is usually made up of two or more primitive or JDK object types.
As you have a composite key, you should use an Embeddable key, there are many examples about it like this, this and this.

Related

JPA entity join column on composite key, with date as one of PK

I have to join two tables with ManyToOne relationship using JPA.
TABLE 1 -> manF
#Entity
#Table(name = "manf")
public class ManF {
#EmbeddedId
private ManFCompositeKey manFCompositeKey;
#Column(name = "name", length = 10)
private String manFName;
#Column(name = "desc", length = 150)
private String manFDesc;
}
#Embeddable
public class ManFCompositeKey {
#Column(name = "man_code", length = 20, nullable = false)
private String manCode;
#Column(name = "update_time", nullable = false)
private Date updTime;
}
TABLE 2 -> products
#Entity
#Table(name = "products")
public class Prod {
#EmbeddedId
private ProdCompositeKey prodCompositeKey;
#Column(name = "name", length = 10)
private String prodName;
#Column(name = "prod_desc", length = 150)
private String prodDesc;
// -> JoinColumn here.
#Column(name = "man_code", length = 20, nullable = false)
private String manCode;
}
#Embeddable
public class ProdCompositeKey {
#Column(name = "prod_code", length = 20, nullable = false)
private String prodCode;
#Column(name = "update_time", nullable = false)
private Date updTime;
}
Now, manF(Table 1) can have many products(Table 2). Thus, for each row in product table, there can be same manFCode.
I intend to establish a join b/w T1 and T2 such that manCode column in products behaves as the FK for this table referenceing man_code of Table 1.
Below is the join condition I wrote:
#ManyToOne(fetch = FetchType.LAZY, optional = false)
#JoinColumns({
#JoinColumn(name = "man_code", referencedColumnName = "man_code")
})
#Column(name = "man_code", length = 20, nullable = false)
private ManF manF;
This should make sense(I thought), but threw an error, stating: ManF not mapped to a single property.
Now I can do this:
#ManyToOne(fetch = FetchType.LAZY, optional = false)
#JoinColumns({
#JoinColumn(name = "man_code", referencedColumnName = "man_code")
#JoinColumn(name = "update_time", referencedColumnName = "update_time")
})
#Column(name = "man_code", length = 20, nullable = false)
private ManF manF;
But then I would be keeping a FK reference on the time, on which a ManF was inserted.
I need to know how can I join the two tables here such that I can create a FK reference on the man_code of ManF table and the man_code in the product (child) table.
You can use hibernate native query and write the join condition. If that is not a option I would particularly change the embeddedId on Manf to a regular id and create a constraint in your db, to maintain integrity an use a regular joincolumn condition. Like this:
SQL: ALTER TABLE 'manf' ADD UNIQUE 'UNIQUE_CONSTRAINT'('man_code', 'update_time');
#Entity
#Table(name = "manf")
public class ManF {
#Id
#SequenceGenerator(name = "SEQUENCE_NAME", sequenceName = "SEQUENCE_NAME", allocationSize = 1, initialValue = 1)
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_NAME")
#Column(name = "man_code", length = 20, nullable = false)
private String manCode;
#Column(name = "update_time", nullable = false)
private Date updTime;
#Column(name = "name", length = 10)
private String manFName;
#Column(name = "desc", length = 150)
private String manFDesc;
}
#Entity
#Table(name = "products")
public class Prod {
#EmbeddedId
private ProdCompositeKey prodCompositeKey;
#Column(name = "name", length = 10)
private String prodName;
#Column(name = "prod_desc", length = 150)
private String prodDesc;
#ManyToOne(fetch = FetchType.LAZY, optional = false)
#JoinColumn(name = "man_code")
private ManF manF;
}
This is what I have done, to achieve this. May be a hack.
I have put the man_code from from Table 1 (ManF), in the main class (it stays is the Embeddable as well). But in the ManF class I did something like this:
#Entity
#Table(name = "manf")
public class ManF {
#EmbeddedId
private ManFCompositeKey manFCompositeKey;
*#Column(name = "man_code", insertable = false, updatable= false)
private String manCode;*
#Column(name = "name", length = 10)
private String manFName;
#Column(name = "desc", length = 150)
private String manFDesc;
}
#Embeddable
public class ManFCompositeKey {
#Column(name = "man_code", length = 20, nullable = false)
private String manCode;
#Column(name = "update_time", nullable = false)
private Date updTime;
}
On the other hand, I have changed my Table 2 as follows:
#Entity
#Table(name = "products")
public class Prod {
#EmbeddedId
private ProdCompositeKey prodCompositeKey;
#Column(name = "name", length = 10)
private String prodName;
#Column(name = "prod_desc", length = 150)
private String prodDesc;
*#ManyToOne(fetch = FetchType.LAZY, optional = false)
#JoinColumns({
#JoinColumn(name = "man_code", referencedColumnName =
"man_code")})
private ManF manF;*
*#Column(name = "man_code", insertable = false, updatable = false)
private String manCode;*
#Column(name = "man_code", length = 20, nullable = false)
private String manCode;
}
#Embeddable
public class ProdCompositeKey {
#Column(name = "prod_code", length = 20, nullable = false)
private String prodCode;
#Column(name = "update_time", nullable = false)
private Date updTime;
}
This is somehow working, but I have had to add a new variable in the Child table (here: manCode with insertable and updatabale as false)
I am not sure if this is the correct approach. Please, let me know if someone has a better and elegant idea to approach this issue.

How to make an entity accessible from two different entities JPA

Hi I am new to JPA and i would like to know if it is possible to map two entities to another entity?
For example lets say i have:
-entity1
public class LieuEnseignement implements Serializable {
#Id
#Column(name = "NO_ORGNS", nullable = false)
private Long noOrganisme;
#Column(name = "NO_ADR_GEOGR")
private Long noAdresseGeographique;
#OneToMany(mappedBy="etabEns", cascade = CascadeType.ALL)
private Set<AdresseGeographique> adresseGeographique;
-entity 2
public class EtablissementEnseignement implements Serializable {
#Column(name = "NO_ORGNS", nullable = false)
private Long noOrganisme;
#Column(name="NO_ADR_GEOGR")
private Long noAdresseGeographique;
#OneToMany(mappedBy="etabEns", cascade = CascadeType.ALL)
private Set<AdresseGeographique> adresseGeographique;
-entity 3
public class AdresseGeographique implements Serializable{
#Column(name="NO_ADR", nullable = false)
private Long noAdresse;
#Column(name="LIGNE1_ADR", nullable = false, length = 40)
private String ligne1AdrGeographique;
#Column(name="LIGNE2_ADR", nullable = false, length = 40)
private String ligne2AdrGeographique;
#Column(name="VILLE", nullable = false, length = 46)
private String villeAdrGeographique;
#Column(name="PROV_PAYS", nullable = false, length = 30)
private String provincePaysAdrGeographique;
#Column(name="CD_POSTAL", nullable = false, length = 6)
private String codePostaleAdrGeographique;
#Column(name="CD_MUNICIPALITE", nullable = false, length = 5)
private String codeMunicipaliteAdrGeographique;
#Column(name="POSTN_X", nullable = false)
private String positionXAdrGeographique;
#Column(name="POSTN_Y", nullable = false)
private String positionYAdrGeographique;
#ManyToOne
#JoinColumn(name = "NO_ADR", referencedColumnName = "NO_ADR_GEOGR", insertable=false, updatable=false)
private EtablissementEnseignement etabEns;
#ManyToOne
#JoinColumn(name = "NO_ADR", referencedColumnName = "NO_ADR_GEOGR", insertable=false, updatable=false)
private LieuEnseignement lieuEns;
So basically entity 1 and 2 call to entity 3 never at the same time. I thought i could just declare two seperate joincolumn but apparently this isn't possible.
edit1: As to why I did not use inheritance for entity 1 and 2 is because they are totally different but I did not put all the data contained within them as i did not find it relevent to the question.
Thanks in advance for your help.

JPA2/Hibernate partial composite primary as a foreign key in one to many relationship

I can't persist the foreign keys on my tables and I think it can be a mapping problem. I am using JPA2/Hibernate4
The data model (unchangeable) is as follows:
OBJECTIVES
==========
INTCODE (PK)
INTOBJECTIVE (PK)
DESCRIPTION
REGISTER
========
INTCODE (PK)
INTREGISTER (PK)
...
INTOBJECTIVE (FK from Objectives)
As you can see in the data model I have a composite primary key in OBJECTIVES table (INTCODE, INTOBJECTIVE) and only one of its fields (INTOBJECTIVE) is a foreign key in REGISTER table.
My JPA mapping clases is as follows:
OBJECTIVES CLASS
#Entity
#Table(name = "OBJECTIVES", uniqueConstraints = #UniqueConstraint(columnNames = "INTOBJECTIVE"))
public class Objectives implements Serializable {
private static final long serialVersionUID = 1L;
#EmbeddedId
#AttributeOverrides({ #AttributeOverride(name = "intcode", column = #Column(name = "INTCODE", nullable = false, length = 2)),
#AttributeOverride(name = "intobjective", column = #Column(name = "INTOBJECTIVE", unique = true, nullable = false, precision = 22, scale = 0)) })
private ObjectivesId id;
#Column(name = "DESCRIPTION")
private String description;
#OneToMany(mappedBy="objective", fetch=FetchType.LAZY, cascade=CascadeType.PERSIST)
private List<Register> registers;
// Constructors, getters and setters ...
OBJECTIVES KEY CLASS
#Embeddable
public class ObjectivesId implements Serializable {
private static final long serialVersionUID = 1L;
#Column(name = "INTCODE", nullable = false, length = 2)
private String intcode;
#Column(name = "INTOBJECTIVE", unique = true, nullable = false, precision = 22, scale = 0)
private BigDecimal intobjective;
// Constructor, getters and setters, ...
REGISTER CLASS
#Entity
#Table(name="REGISTER", uniqueConstraints = #UniqueConstraint(columnNames = "INTREGISTER"))
public class Register {
#EmbeddedId
#AttributeOverrides({ #AttributeOverride(name = "intcode", column = #Column(name = "INTCODE", nullable = false, length = 2)),
#AttributeOverride(name = "intregister", column = #Column(name = "INTREGISTER", unique = true, nullable = false, precision = 22, scale = 0)) })
private RegisterId id;
#ManyToOne
#JoinColumns({
#JoinColumn(name="INTCODE", referencedColumnName="INTCODE", insertable=false, updatable=false),
#JoinColumn(name="INTOBJECTIVE", referencedColumnName="INTOBJECTIVE", insertable=false, updatable=false)
})
private Objectives objective;
// Constructor, getter and setters, ...
REGISTER KEY CLASS
#Embeddable
public class RegisterId implements Serializable {
private static final long serialVersionUID = 1L;
#Column(name = "INTCODE", nullable = false, length = 2)
private String intcode;
#Column(name = "INTREGISTER", unique = true, nullable = false, precision = 22, scale = 0)
private BigDecimal intregister;
// Constructor, getters and setters, ...
Is it posible to perform this in Hibernate4?

eclipselink SQLServerException inserting into a join table with additional column

I have a many-to-many relationship which looks like this:
The primary key is combination of three columns and I'm using eclipselink. I created these classes to be able to insert in the join-table :
#Entity
#Table(name = "definition_property")
#NamedQueries({
#NamedQuery(name = "DefinitionProperty.findAll", query = "SELECT d FROM DefinitionProperty d")})
public class DefinitionProperty extends AbstractEntity{
private static final long serialVersionUID = 1L;
#EmbeddedId
protected DefinitionPropertyPK pk;
#JoinColumn(name = "dtid", referencedColumnName = "id", insertable = false, updatable = false)
#ManyToOne(optional = false)
private DefinitionType definitionType;
#JoinColumn(name = "prid", referencedColumnName = "id", insertable = false, updatable = false)
#ManyToOne(optional = false)
private Property property;
#Column(name = "initial_value")
#Basic(optional = false)
private String initialValue;
// setters and getters
}
And PK class:
#Embeddable
public class DefinitionPropertyPK implements Serializable{
#Column(name = "dtid")
private Integer idDt;
#Column(name = "prid")
private Integer idProperty;
#Column(name = "initial_value")
private String initialValue;
//hashcode, equals, setters and getters
}
Entitiy 1:
#Entity
#Table(name = "definition_type")
public class DefinitionType extends AbstractEntity implements EntityItem<Integer> {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Basic(optional = false)
#Column(name = "id")
private Integer idDT;
#Size(max = 45)
#Column(name = "name")
private String dtName;
#Size(max = 45)
#Column(name = "description")
private String description;
#OneToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "definitionType")
private List<DefinitionProperty> definitionProperties = new ArrayList<DefinitionProperty>();
}
Entity 2:
#Entity
#Table(name = "property")
public class Property extends AbstractEntity implements EntityItem<Integer>{
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.SEQUENCE)
#Basic(optional = false )
#Column(name = "id")
private Integer idProperty;
#Column(name = "name")
#Size(max = 45)
private String propertyName;
#Enumerated(EnumType.STRING)
#Column(name = "type")
private Type fieldType;
#Column(name = "init_value")
#Size(max = 45)
private String initialValue;
#OneToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "property")
private List<DefinitionProperty> definitionPeoperties= new ArrayList<DefinitionProperty>();
}
Exception : I get this exception when trying to persist a new DefinitionType:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The column name 'initial_value' is specified more than once in the SET clause. A column cannot be assigned more than one value in the same SET clause. Modify the SET clause to make sure that a column is updated only once. If the SET clause updates columns of a view, then the column name 'initial_value' may appear twice in the view definition.
Error Code: 264
Call: INSERT INTO definition_property (initial_value, initial_value, dtid, prid) VALUES (?, ?, ?, ?)
bind => [4 parameters bound]
Question : Why there are two initial_values in the set clause and where am I wrong in my code?
Ref: How do you Set Up a Many-to-Many Relationship with Junction Table using JPA/EclipseLink
Ref: JPA simple many-to-many with eclipselink
Ref: https://giannigar.wordpress.com/2009/09/04/mapping-a-many-to-many-join-table-with-extra-column-using-jpa/

Hibernate MS SQL Join issue

I have two tables in the clients mssql database. The first is a job table - so I created an Job entity which contains the load type and load weight and all that stuff - works fine.
My problem now is that there is a second table that includes informations about the load and unload point. The second table, I call it JEP, has a primary key consisting of several items: the type (load or unload), the zip code and the customer number.
I created an entity JobEndPoint and NetBeans also created an object representing the primary key JobEndPointPK containing all that fields.
I want to add two JobEndPoint (loadPoint and unloadPoint) to my Job entity. My problem is now: how do I annotate that in Hibernate? In my opinion it is an #OneToOne relation ship. It would be perfect if I could specify a SELECT statement like SELECT * FROM JEP WHERE type="load" AND customer_nr="123" AND zip_code="123 ...". Is that possible with Hibernate?
Thanks for your help!
Regeards,
Marco
Here are the Entities:
#Entity
#Table(name = "Auftragsdaten", catalog = "...", schema = "dbo")
public class Job implements Comparable<Object>, Serializable {
private static final long serialVersionUID = 4285871251915951149L;
#Id
#Basic(optional = false)
#Column(name = "`id`", nullable = false)
int id;
#Column(name = "`AufNr`", nullable=false)
int jobId;
#Transient
List<Integer> jobsAdded;
#Column(name = "`Beladedatum`", nullable=false)
#Temporal(TemporalType.DATE)
Date loadDate;
#Column(name = "`Beladezeit`")
#Temporal(TemporalType.TIME)
Date loadTimeFrom;
#Transient
Date loadTimeTo;
#Column(name = "`Entladedatum`", nullable=false)
#Temporal(TemporalType.DATE)
Date unloadDate;
#Column(name = "`Entladezeit Beginn`")
#Temporal(TemporalType.TIME)
Date unloadTimeFrom;
#Column(name = "`Entladezeit Ende`")
#Temporal(TemporalType.TIME)
Date unloadTimeTo;
#Transient
List<JobEndPoint> froms;
#OneToOne
#JoinColumns ({
#JoinColumn(name="`Beladetyp`", referencedColumnName = "`Ladetyp`", insertable = false, updatable = false),
#JoinColumn(name="`AbsNr`", referencedColumnName = "`KundenNr`", insertable = false, updatable = false),
#JoinColumn(name="`Verkehrsart`", referencedColumnName = "`VerkArt`", insertable = false, updatable = false),
#JoinColumn(name="`von LKZ`", referencedColumnName = "`LKZ`", insertable = false, updatable = false),
#JoinColumn(name="`von PLZ`", referencedColumnName = "`PLZ`", insertable = false, updatable = false)
})
JobEndPoint fromPoint;
#Transient
JobEndPoint toPoint;
#Column(name = "`Verkehrsart`", length = 10, nullable=false)
#Enumerated
JobType type;
#Column(name = "`Anzahl Paletten CCG1`")
int numberCCG1;
#Column(name = "`Anzahl Paletten CCG2`")
int numberCCG2;
#Transient
int numberFullContainer;
#Transient
int numberEmptyContainer;
#Column(name = "`Anzahl Container`")
int numberContainer;
#Column(name = "`Anz Stellplätze`")
int numberUnits;
#Column(name = "`Bruttogewicht`", nullable=false)
int loadWeight;
#ManyToOne
#JoinColumn(name="`Kühlkennzeichen`")
CoolingCode coolingCode;
}
#Entity
#Table(name = "BES", catalog = "...", schema = "dbo")
public class JobEndPoint implements Serializable {
private static final long serialVersionUID = 1017986852824783744L;
#Id
protected JobEndPointPK jobEndPointPK;
(...)
}
#Embeddable
public class JobEndPointPK implements Serializable {
#Basic(optional = false)
#Column(name = "`Ladetyp`", nullable = false, length = 50)
#Enumerated
EndPointType type;
#Basic(optional = false)
#Column(name = "`KundenNr`", nullable = false)
int customerId;
#Basic(optional = false)
#Column(name = "`VerkArt`", nullable = false, length = 10)
#Enumerated
JobType jobType;
#Basic(optional = false)
#Column(name = "`LKZ`", nullable = false, length = 3)
String countryCode;
#Basic(optional = false)
#Column(name = "`PLZ`", nullable = false, length = 7)
String zipCode;
}
In general, I would recommend using a generated internal primary key instead of the composite key. However, if you need to stick with your composite key, here are some ideas that hopefully help.
I understand that JobEndPointPK is implemented as an identifier component (see the Hibernate Reference, chapter 8.4). Note: it is critical that it implements the equals and hashCode` methods correctly, as Hibernate relies on these.
Updated: Provided that your JobEndPoint and JobEndPointPK looks something like this:
#Embeddable
class JobEndPointPK {
#Column(name = "type", nullable = false)
#Enumerated
EndPointType type;
#Column(name = "zipCode", nullable = false)
String zipCode;
#Column(name = "customerNumber", nullable = false)
int customerId;
// equals, hasCode, getters, setters etc.
}
#Entity
class JobEndPoint {
#Id
private JobEndPointPK key;
// getters, setters etc.
}
The mapping annotation would be something like:
#Entity
class Job {
#OneToOne
#JoinColumns ({
#JoinColumn(name="loadPointType", referencedColumnName = "type"),
#JoinColumn(name="loadPointZip", referencedColumnName = "zipCode"),
#JoinColumn(name="loadPointCust", referencedColumnName = "customerNumber")
})
private JobEndPoint loadPoint;
// similarly for unloadPoint
// other properties
}
The example is adapted from here.
I am not sure how to deal with JobEndPointPK.type though, as for loadPoint it is obviously Load and for unloadPoint, Unload, so you most probably don't want to store it separately in the DB. My gues is that you can specify the value with the #Formula annotation, but I haven't seen any concrete example for this.
Note that all this code is purely experimental, I haven't tested it.
There are other variations on the theme. For more details, see the section "Composite keys with annotations" in Chapter 8 of Java Persistence with Hibernate.

Categories