openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christian Defoy" <>
Subject Skip a computed field on insert and update
Date Thu, 30 Aug 2007 15:16:49 GMT

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!


View raw message