-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: ManyToOne in Composite Identifier causing error on Sybase 12
PostPosted: Wed Oct 11, 2006 6:14 pm 
Newbie

Joined: Wed Oct 11, 2006 5:11 pm
Posts: 4
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 6:55 pm 
Newbie

Joined: Thu Aug 10, 2006 12:25 am
Posts: 13
Hi

not sure about the embeded syntax but I have done similiar things with xml files


<many-to-one name="createdUserid" not-null="true" class="DBUser" outer-join="false" />

the attribute not-null is the one that you are after

but I am guess something like

@ManyToOne( not-null={false})


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 7:01 pm 
Newbie

Joined: Wed Oct 11, 2006 5:11 pm
Posts: 4
Thanks for the tip!!! You led me to the right track.
The answer is:

Code:
@ManyToOne( optional=false )


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.