Hi,
I think that you want to do the following:
> @ManyToOne( fetch=FetchType.LAZY )
> @Column( name="shape_id" )
> private Shape shape;
@Column( name="shape_id", insertable=false, updatable=false )
That will tell OpenJPA to not insert or update those columns.
-Patrick
On 8/30/07, Christian Defoy <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I have a Shape object that is referred to by an Attachment object.
> The ID for Attachment is computed based on the ID of the related Shape
> and the database enforces that by having the Attachment.shape_id field
> as a computed field.
>
> create table Shape
> (
> shape_id int identity not null primary key
> );
>
> create table Attachment
> (
> attachment_id int not null primary key,
> shape_id as (attachment_id / 65536),
> name varchar(20)
> );
>
> (Note: the DB is SQL Server)
>
> The Attachment object has a reference to the Shape object but I must
> prevent OpenJPA from trying to persist that reference to the database.
> However, OpenJPA must be able to load the Shape when I load the
> Attachment. Is that possible? If so, how do I do that?
>
> I use the following annotations in Attachment to refer to Shape, but
> that only gets me an exception.
>
> @ManyToOne( fetch=FetchType.LAZY )
> @Column( name="shape_id" )
> private Shape shape;
>
> The exception is:
>
> org.apache.openjpa.lib.jdbc.ReportingSQLException: Column 'shape_id'
> cannot be modified because it is a computed column. {prepstmnt
> 30638546 INSERT INTO attachment (attachment_id, name, shape_id) VALUES
> (?, ?, ?) [params=(int) 1900544, (String) MyAttach, (int) 29]}
> [code=271, state=S0001]
>
> Thanks in advance!
>
> Christian
>
--
Patrick Linskey
202 669 5907