Mnesia exception output: {aborted, {bad_type, Record}}

I am creating a table whose name does NOT match its record name. Below is a snippet of code

%% ---- record definition --------------------------------
-record (object, {key, value}).
%% ---- create table ------------------------------------- {atomic, ok} = mnesia: create_table (mytable, [ {type, set}, {frag_properties, [ {node_pool, [node ()]}, {n_fragments, 4}, {n_disc_copies, 1}]}, {attributes, record_info (fields, object)}] ),

%% ------- inserting --------------------------------
insert () -> F = fun () -> R = #object { key = "MyKey", value = "Value" }, mnesia: write (mytable, R, write) end mnesia: activity (transaction, F, [], mnesia_frag).
By doing this, the monsieur screams loudly with execution. The table is created very well and can be viewed in tv:start().or in mnesia:info().. This is the error that I see in my shell.
** exception exit: {aborted,
                       {bad_type,
                           #object {
                               key = "MyKey",
                               value = "Value"}}}
     in function mnesia: wrap_trans / 6 (mnesia.erl, line 395)
Now, as a rule, I thought that such an error would occur when the record definition used to create the table is different from the structure of the record inserted into the table. Interestingly, this is just a problem with the function I use, that is:, mnesia:write/3which helps when the table name is different from the record name.

I tried to delete the circuit and recreate it, but all in vain. When I do not use mnesia:write/3, the record will be correctly inserted into the table. But my application needs are such that I will have several different tables that are created, but they retain the same record structure / definition. I want to have different tables, but their definition record_infois the same.

Somewhere in the documents, I read that this is very possible. I am running: Erlang otp R15B, mnesia-4.6 , windows 7 enterprise, 32-bit operating system, Dell laptop, intel core i5, 4GB RAM All the other erlang projects that I'm working on are fine, they don't have any unexpected or unexpected behavior like this.
Any suggestions?
+3
source share
1 answer

When creating a table, you must use the property {record_name, object}. eg.

{atomic,ok} = mnesia:create_table(mytable,[
                {type,set},
                {frag_properties,[
                            {node_pool,[node()]},
                            {n_fragments,4},
                            {n_disc_copies,1}]},
                {record_name, object},
                {attributes,record_info(fields,object)}]
            ),

From docs :

{username, name}, where Name must be an atom. All records stored in the table must have this name as the first element. By default, the same name as the table name is used.

+8
source

All Articles