Hi all,
i'm using hibernate in connection with EJB 3.0, JBoss 4.0.4 and MySQL 5.0.22. I my case there are two objects/tables using composite PKs. The second PK contains a part of the FK of the first object. The Primary Keys are annotate by the @EmbeddedId tag. If i want to deploy my application on JBoss i get the following exception in my server log file.
org.hibernate.MappingException: Repeated column in mapping for entity: xx.xx.xx.xx.Reservation column: DATUM (should be mapped with insert="false" update="false")
Any suggestions? . Thank you in advance.
Dirk
Environment:
Hibernate EntityManager 3.2.0.CR1
Hibernate Annotations 3.2.0.CR1
Hibernate 3.2 cr2
Sources:
Table 1 - Cruise.java
Table 2 - Reservation.java
PK implementation - CruisePK.java, Reservation.java
Cruise.java
Code:
@Entity
@Table(name = "CRUISE")
public class Cruise
{
private int _id;
private String _name = "";
private String _owner = "";
private String _date = "";
private int _shipId;
private Collection<Reservation> _reservations = new ArrayList<Reservation>();
private CruisePK _pk;
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name="id", column=@Column(name="ID")),
@AttributeOverride(name="date", column=@Column(name="DATUM"))
})
public CruisePK getPk() { return _pk; }
public void setPk( CruisePK pk ) { _pk = pk; }
@Column(name = "NAME")
public String getName()
{
return _name;
}
public void setName(String name)
{
_name = name;
}
@Column(name="OWNER")
public String getOwner() {
return _owner;
}
public void setOwner(String owner){
_owner = owner;
}
@Column(name = "SHIPID")
public int getShipId()
{
return _shipId;
}
public void setShipId(int id)
{
_shipId = id;
}
@OneToMany(mappedBy = "cruise", cascade={ CascadeType.PERSIST, CascadeType.MERGE })
public Collection<Reservation> getReservations()
{
return _reservations;
}
public void setReservations(Collection<Reservation> reservations)
{
_reservations = reservations;
}
}
Reservation.java
Code:
@Entity
@Table(name = "RESERVATION")
public class Reservation
{
private int _id;
private String _date = "";
private String _amount = "";
private Cruise cruise;
private ReservationPK _pk;
public Reservation(){};
public Reservation(Cruise cr) {cruise = cr;}
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name="id", column=@Column(name="ID")),
@AttributeOverride(name="date", column=@Column(name="DATUM", updatable=false, insertable=false))
})
public ReservationPK getPk() { return _pk; }
public void setPk( ReservationPK pk ) { _pk = pk; }
@Column(name = "AMOUNT")
public String getAmount()
{
return _amount;
}
public void setAmount(String amount)
{
_amount = amount;
}
@ManyToOne
@JoinColumns({
@JoinColumn(name = "CRUISE_ID", referencedColumnName="ID"),
@JoinColumn(name = "DATUM", referencedColumnName="DATUM")
})
public Cruise getCruise()
{
return cruise;
}
public void setCruise(Cruise cr)
{
cruise = cr;
}
}
CruisePK.java
Code:
@Embeddable
public class CruisePK implements Serializable {
private String _date = "";
private int _id;
public CruisePK() {};
public CruisePK(String date, int id){
_date = date;
_id = id;
}
public String getDate() { return _date; }
public void setDate(String date) { _date = date; }
public int getId() { return _id; }
public void setId(int id) { _id = id; }
public boolean equals(Object obj){
if (obj == this) {
return true;
}
if ( !( obj instanceof CruisePK ) ) {
return false;
}
CruisePK pk = (CruisePK)obj;
if (!_date.equals(pk.getDate())) {
return true;
}
if (_id != pk.getId()) {
return false;
}
return true;
}
public int hashCode() {
if ( _date == null ) {
return 0;
}
return (_date.hashCode() * 29) + _id * 31;
}
}
ReservationPK.java
Code:
@Embeddable
public class ReservationPK implements Serializable {
private String _date = "";
private int _id;
public ReservationPK() {};
public ReservationPK(String date, int id){
_date = date;
_id = id;
}
public String getDate() { return _date; }
public void setDate(String date) { _date = date; }
public int getId() { return _id; }
public void setId(int id) { _id = id; }
public boolean equals(Object obj){
if (obj == this) {
return true;
}
if ( !( obj instanceof CruisePK ) ) {
return false;
}
CruisePK pk = (CruisePK)obj;
if (!_date.equals(pk.getDate())) {
return true;
}
if (_id != pk.getId()) {
return false;
}
return true;
}
public int hashCode() {
if ( _date == null ) {
return 0;
}
return (_date.hashCode() * 30) + _id * 32;
}
}