Hi Derek,

On 2 Mar 2008 at 17:13, Derek Broughton wrote:

> Clearly I'm misunderstanding something in the way this works.
> 
> Having received the error:
>  Error casting value for table 'glaccount' and column 'gltype_id'
> no matter what I put in src/test/resources/sample-data.xml for the gltype_id
> column (it's defined in postgres as "bigint" and the numbers it's trying to
> use are -1 or -2), I finally decided to just remove that column altogether
> from the sample-data.xml file.  That must be the right file, as removing it
> results in a different error.
> 
> Then I got: 
> Embedded error: org.postgresql.util.PSQLException: ERROR: insert or update
> on table "glaccount" violates foreign key constraint "fk345b21a830ba0cef"
>   Detail: Key (parent_id)=(1) is not present in table "glaccount".
> 
> Yet, there's no value (1) anywhere in the sample data!  This is a simple
> self-referential table, where parent_id is a reference to the parent key.
> Am I missing some required definition in the model for the top of the
> hierarchy - the account with no parent?

I'm not sure, but I wonder if your "accountnum" column is being interpreted 
as a parent_id as the order of your data is different from the order of 
columns you've defined.  I know there are column names in a "description" 
attribute in the "value" but I'm not sure they're actually used to actually 
align 
the enclosed data with the columns.  I'd try making sure your data values are 
in the same column order as that in your <table> attribute

> The postgres definition is:
>              Table "public.glaccount"
>    Column    |          Type          | Modifiers
> -------------+------------------------+-----------
>  id          | bigint                 | not null
>  name        | character varying(255) |
>  description | character varying(255) |
>  accountnum  | character varying(255) |
>  parent_id   | bigint                 |
>  gltype_id   | bigint                 |
> 
> and the sample data is:
>     <!--Glaccount-START-->
>     <table name="glaccount">
>         <column>id</column>
>         <column>parent_id</column>    
>         <column>accountnum</column>
>         <column>name</column>
>         <column>description</column>
>     <row>
>         <value description="id">-1</value>
>         <value description="accountnum">1</value>
>         <value description="name">Assets</value>
>         <value description="description">All Asset Accounts</value>
>     </row>

WRT your second problem, if I'm right about the way the data is being 
interpreted, then in your first row of data, it's taking the "accountnum" value 
of 1 trying to insert into the parent_id column, not finding the related parent 
record in the table and then barfing.

Carrying on a bit further, still assuming I'm right, if the parent_id value 
worked, the next data value is a string which DBUnit would try and put into 
the accountnum column, which may account for your casting error.  You 
should normally see more detail about this in the error logs in your project's 
target/surefire-reports directory.

HTH,
Rob Hills
Waikiki, Western Australia
Mobile +61 (412) 904-357
Fax: +61 (8) 9529-2137


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to