Hibernate version: 3.2
Name and version of the database: Sybase 12.5
I have have three objects of interest.
1. an Entity called mkt_Index
2. an Embeddable called mkt_ForwardCurveKey that contains an mkt_Index (which I desire to be ManyToOne)
3. an Entity called mkt_ForwardCurvePoint that contains an mkt_ForwardCurveKey as its Composite Identifier.
The problem I am encountering is as follows.
The SQL generated for mkt_ForwardCurvePoint for Sybase 12.5 fails on execution. It won't allow a nullable column as part of the primary key.
It is nullable apparently because of the ManyToOne relationship, and I can't seem to turn that off by using a Column( nullable=false) either.
a) am I wrong to be designating this field as ManyToOne? Should I be doing something differently there?
b) Is this something I just have to live with and use my own SQL to generate the table?
In brief, my classes look like this:
Code:
@Entity
public class mkt_Index
implements Serializable
{
@Id
private Long d_id = null;
@Column( length=20 )
private String d_shortName = null;
protected mkt_Index()
{
}
public int hashCode()
{
return d_id.intValue();
}
public boolean equals( Object obj )
{
if( false == obj instanceof mkt_Index )
return false;
return d_id == ((mkt_Index)obj).d_id;
}
}
@Embeddable
public class mkt_ForwardCurveKey implements Serializable
{
private Date d_asOfTime;
@ManyToOne
private mkt_Index d_index;
public mkt_ForwardCurveKey()
{
}
public int hashCode()
{
return d_index.hashCode() * d_asOfTime.hashCode();
}
public boolean equals( Object obj )
{
mkt_ForwardCurveKey rhs = (mkt_ForwardCurveKey)obj;
return d_index.getId().equals( rhs.d_index.getId() )
&& d_asOfTime.equals( rhs.d_asOfTime );
}
}
@Entity
public class mkt_ForwardCurvePoint
{
@EmbeddedId
private mkt_ForwardCurveKey d_key;
private double d_value;
public mkt_ForwardCurvePoint()
{
}
public mkt_ForwardCurveKey getKey()
{
return d_key;
}
}
The generated SQL:Code:
-- this one is fine...
create table mkt_DummyIndex (id numeric(19,0) not null, shortName varchar(20) null, primary key (id))
-- this one generates an error on Sybase 12.5
create table mkt_ForwardCurvePoint (asOfTime datetime not null, value double precision not null, indexId numeric(19,0) null, primary key (asOfTime, indexId))
The Sybase error:Code:
Column 'indexId' is part of a primary key constraint and cannot be null.
Failed to create declarative constraints on table 'mkt_ForwardCurvePoint' in
database 'powerDev'.
If I add a @Column( nullable=false )Code:
Caused by: org.hibernate.AnnotationException: @Column(s) not allowed on a @ManyToOne property: com.sac.power.bo.mkt.dropZone.mkt_ForwardCurvePoint.d_key.d_index