JDOUserException when persisting object: supposedly incorrect type is same as expected type - jdo

Trying to persist an object results in this exception being thrown. It complains about an incorrect type but then expects that same type. The exception started appearing after renaming the project from dbd2012_p2 to dbd2012_p3 (it's a continuation from the previous assignment).
I have found no information on Google about this exception. I've gone through the metadata files making sure there are no instances of dbd2012_p2 left behind and I am now stumped.
Our database is basically a many-to-many relationship: Prova with Tag. Mesura models the relationship with a few extra attributes (activity, datetime, x, y and z coords).
Exception
javax.jdo.JDOUserException: The owner field prova of element class dbd2012_p3.Mesura has an incorrect type "dbd2012_p3.Prova". Should be "dbd2012_p3.Prova"
javax.jdo.JDOUserException: The owner field prova of element class dbd2012_p3.Mesura has an incorrect type "dbd2012_p3.Prova". Should be "dbd2012_p3.Prova"
at org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:519)
at org.datanucleus.api.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:736)
at org.datanucleus.api.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:756)
...
at dbd2012_p3.dbd2012_p3.main(dbd2012_p3.java:28)
Code
for (String name : names) {
for (String seq : seqs) {
Prova prova = new Prova(name, seq);
pm.makePersistent(prova); // Exception thrown here
}
}
Prova.java
#PersistenceCapable
public class Prova {
#PrimaryKey //OJO
private String nom_persona = null;
#PrimaryKey
private String num_seq = null;
private Set tagRelations = new HashSet();
public Prova(String nou_nom_persona, String nou_num_seq) {
nom_persona = nou_nom_persona;
num_seq = nou_num_seq;
}
public Prova(){}
package-mysql.orm
This is how we have our tables defined:
<?xml version="1.0"?>
<!DOCTYPE orm SYSTEM "file:/javax/jdo/orm.dtd">
<orm>
<package name="dbd2012_p3">
<class name="Prova" type="application" table="prova">
<field name="nom_persona" primary-key="true">
<column name="nom_persona" length="45" jdbc-type="VARCHAR"/>
</field>
<field name="num_seq" primary-key="true">
<column name="num_seq" length="45" jdbc-type="VARCHAR"/>
</field>
<field name="tagRelations" persistence-modifier="persistent" mapped-by="prova">
<collection element-type="Mesura" />
</field>
</class>
<class name="Tag" type="application" table="tag">
<field name="codi" primary-key="true">
<column name="codi" length="45" jdbc-type="VARCHAR" />
</field>
<field name="nom">
<column name="nom" length="45" jdbc-type="VARCHAR" />
</field>
<field name="provaRelations" persistence-modifier="persistent" mapped-by="tag">
<collection element-type="Mesura" />
</field>
</class>
<class name="Mesura" type="datastore" table="mesura">
<field name="datetime" column="datetime"/>
<field name="prova" />
<field name="tag" />
<field name="activitat" />
<field name="x">
<column name="x" jdbc-type="DECIMAL" length="3" scale="1" />
</field>
<field name="y">
<column name="y" jdbc-type="DECIMAL" length="3" scale="1" />
</field>
<field name="z">
<column name="z" jdbc-type="DECIMAL" length="3" scale="1" />
</field>
</class>
</package>
</orm>
Note: I haven't tagged this as homework because the assignment is about applying data mining techniques to the data we add into the database. I can just rename the project back to its old name and it works again, but the exception is really bugging me.

Related

how to create a button that opens a popup without automatic registration / creation of the form odoo13

I want to create a button that opens a popup that takes over some form fields.
These fields can be modified / filled in.
When closing the fields concerned are updated.
without saving or creating the record before I click on the save button.
I don't see how to get there knowing that there are no relational fields.
Should I create a widget, a wizard, both ....
Help me please.
Here is my current code :
test_scale.py :
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class TestScale(models.Model):
_name = 'test.scale'
name = fields.Char(required=True)
weighing = fields.Integer('weighing', default=0)
test_scale.xml :
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="test_scale_tree_view" model="ir.ui.view">
<field name="name">test.scale.tree</field>
<field name="model">test.scale</field>
<field name="arch" type="xml">
<tree string="Test scale">
<field name="name"></field>
<field name="weighing"></field>
</tree>
</field>
</record>
<record id="test_scale_form_view" model="ir.ui.view">
<field name="name">test.scale.form</field>
<field name="model">test.scale</field>
<field name="arch" type="xml">
<form string="Test scale">
<sheet>
<group name="main_info">
<field name="name"></field>
<field name="weighing"></field>
<button name="%(test_scale_configurator_action)d"
type="action"
string="Weighing"
class="oe_highlight"
context="{'weighing': weighing}"></button>
</group>
</sheet>
</form>
</field>
</record>
<record id="saisie_menu_action" model="ir.actions.act_window">
<field name="name">Test_scale</field>
<field name="res_model">test.scale</field>
<field name="type">ir.actions.act_window</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Aucun enregistrement
</p>
</field>
</record>
<menuitem id="test_scale_menu"
name="Test_scale"/>
<menuitem id="test_scale_saisie_menu"
parent="test_scale_menu"
name="Saisie"
action="saisie_menu_action"/>
</odoo>
test_scale_configurator.xml :
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="test_scale_configurator_view_form" model="ir.ui.view">
<field name="name">test.scale.configurator.view.form</field>
<field name="model">test.scale.configurator</field>
<field name="arch" type="xml">
<form>
<field name="weighing"/>
<footer>
<button type="object"
name="button_save"
string="Save"
/>
<button special="cancel"
string="Cancel"
class="btn-secondary"/>
</footer>
</form>
</field>
</record>
<record id="test_scale_configurator_action" model="ir.actions.act_window">
<field name="name">Test Scale</field>
<field name="res_model">test.scale.configurator</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="view_id" ref="test_scale_configurator_view_form"/>
</record>
</odoo>
test_scale_configurator.py :
# -*- coding: utf-8 -*-
from odoo import models, fields
class TestScaleConfigurator(models.TransientModel):
_name = 'test.scale.configurator'
weighing = fields.Integer(string='weighing')
def button_save(self):
self.ensure_one()
return True
This thing is done by relational fields of odoo , For EX:-
In your test.scale model your field is weighing,
First you need to configure your current model test.scale 's id in wizard so you can reference it, like this you can add the field in wizard.
test_scale_id = fields.Many2one(string="Test Scale")
After that add context in you main model's xml file where is the button which one opens the wizard like this.
<button name="%(test_scale_configurator_action)d"
type="action"
string="Weighing"
class="oe_highlight"
context="{'default_test_scale_id': active_id}"></button>
After that this field needs to be invisible in your wizard's form in order to save data in wizard so you can refernce it later.
<field name="test_scale_id" invisible="1"/>
and in your wizard weighing field is stayed like this.
weighing = fields.Integer(string='weighing', related='test_scale_id.weighing', readonly=False)
Note: This process , making field is one time process.
after that you can use any field which is in your main model and you want to use in wizard you can get those fields by test_scale_id.any_of_your_field.

How to add cascade argument in XML file format doctrine ORM

as far as I understand I need to add a "cascade" parameter to the mapping. But my mapping is in XML.
I found quite a bit of information about it but there was no result.
Pleace help!
Мy error is:
Multiple non-persisted new entities were found through the given association graph:\n\n * A new entity was found through the relationship 'Domain\Maintenance\Maintenance#affectedRegions' that was not configured to cascade persist operations for entity: Domain\AffectedRegion\AffectedRegion#0000000075384ba200000000535ab7f1. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example #ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem implement 'Domain\AffectedRegion\AffectedRegion#__toString()' to get a clue.\n *
XML fails:
<entity name="Domain\Maintenance\Maintenance" table="maintenances" repository-class="Infrastructure\Repositories\MaintenanceRepository">
<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
</id>
<field name="name" type="string"/>
<one-to-many field="affectedRegions" target-entity="Domain\AffectedRegion\AffectedRegion" mapped-by="Domain\Maintenance\Maintenance" />
<cascade>
<cascade-merge/>
</cascade>
</entity>
<entity name="Domain\AffectedRegion\AffectedRegion" table="affected_regions" repository-class="Infrastructure\Repositories\AffectedRegionRepository">
<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
</id>
<many-to-one field="region" target-entity="Domain\Region\Region" inversed-by="Domain\AffectedRegion\AffectedRegion">
<join-column name="region_id" referenced-column-name="id" />
<cascade>
<cascade-persist/>
</cascade>
</many-to-one>
<many-to-one field="maintenance" target-entity="Domain\Maintenance\Maintenance" inversed-by="Domain\AffectedRegion\AffectedRegion">
<join-column name="maintenance_id" referenced-column-name="id" />
<cascade>
<cascade-persist/>
</cascade>
</many-to-one>
<field name="vlans" type="string"/>
<field name="olts" type="string"/>
</entity>
<entity name="Domain\Region\Region" table="regions" repository-class="Infrastructure\Repositories\RegionRepository">
<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
</id>
<field name="name" type="string"/>
<field name="code" type="string"/>
<one-to-many field="affectedRegions" target-entity="Domain\AffectedRegion\AffectedRegion" mapped-by="Domain\Maintenance\Maintenance" />
</entity>
this is my FK:
$affectedRegionTable->addForeignKeyConstraint(
$regionTable,
['region_id'],
['id'],
['onUpdate' => 'CASCADE'],
'fk_affectedRegions_region_id'
);
$affectedRegionTable->addForeignKeyConstraint(
$regionTable,
['maintenance_id'],
['id'],
['onUpdate' => 'CASCADE'],
'fk_affectedRegions_maintenance_id'
);
the relation I want to make is:
Maintenance ← one-to-many → AffectedRegions ← many-to-one → Region
Here is the answer.
Another way to add a cascade argument:
<one-to-many field="affectedRegions" target-entity="Domain\AffectedRegion\AffectedRegion" mapped-by="maintenance">
<cascade>
<cascade-persist/>
<cascade-remove/>
</cascade>
</one-to-many>

How can add new fields inside crm.lead model via custom module inheriting crm.lead model in odoo 11?

According to requirements, need to customize Contact Us form which inserts into CRM.lead model (CRM module - Odoo 11)
I need to add additional fields in this model.
Issue! Already added new fields in this model but now showing on form view.
<record id="crm_case_form_view_leads_inherited" model="ir.ui.view">
<field name="name">crm.lead.form.lead.inherited</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_leads" />
<field name="arch" type="xml">
<notebook position="inside">
<page string="Extra fields">
<group>
<field name="field_x"/>
<field name="field_y"/>
<field name="field_z"/>
</group>
</page>
</notebook>
</field>
class Lead(models.Model):
_inherit = 'crm.lead'
field_x = fields.Char(string='Field X)
field_y = fields.Text(string='Field Y')
field_z = fields.Char(string='Field Z')
Problem is not showing fields values on form view.
Check this link which appears as issue :
https://drive.google.com/file/d/1ZoqU2REHlpwJm_oQ7mXJmNJSqF8v22KA/view
<record id="crm_case_form_view_leads_inherited" model="ir.ui.view">
<field name="name">crm.lead.form.lead.inherited</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_oppor" />
<field name="arch" type="xml">
<xpath expr="//page[#name='lead']" position="after">
<page string="Extra fields">
<group>
<field name="field_x"/>
<field name="field_y"/>
<field name="field_z"/>
</group>
</page>
</xpath>
</field>

Configure Solr Index With File Metadata using TikaEntityProcessor & FieldStreamDataSource

I have created an index that pulls data from a SQL Server database using TikaEntityProcessor. The query associated with my configuration file pulls from a table containing file information, as well as the file content as a binary column. My index returns all fields from the database table in which I have configured, as well as the column for "text" that is the body of the file content. It correctly indexes the file text! However, the meta columns are not working! You can see I have a field for text/body, this works fine. However, I cannot get any metadata from the file such as last modified date or author.
Any suggestions would be greatly appreciated!!
data-config:
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://server;databaseName=db1;integratedSecurity=false"
user="user"
password="XXXXXX" convertType="false"
name="ds"/>
<dataSource name="fieldReader"
type="FieldStreamDataSource" />
<document name="tika">
<entity name="tika" pk="id" transformer="TemplateTransformer" dataSource="ds"
query="select id, title from myDatabaseTable">
<entity name="tika-test" processor="TikaEntityProcessor" dataSource="fieldReader"
dataField="tika.FileContent" format="text">
<field column="text" name="body"/>
<field column="Last-Modified" name="lastModified" meta="true" /> <!-- not working -->
</entity>
</entity>
</document>
</dataConfig>
schema:
<field name="id" type="integer" indexed="true" stored="true" />
<field name="body" type="text" indexed="true" stored="true" />
<field name="lastModified" type="text" indexed="true" stored="true" />
<field name="title" type="text" indexed="true" stored="true" />
Thanks!!

How to rename an attribute in XML?

i have XMl like
<record id="1" name="CustomerInfo">
<field name="id" index="1" type="String"/>
</record>
i want to rename "name" attribute to "match" like
<record id="1" match="CustomerInfo">
<field match="id" index="1" type="String"/>
</record>
You can add a new field based on the old one and then delete the old :
var xml:XML = <record id="1" name="CustomerInfo">
<field name="id" index="1" type="String"/>
</record>;
// create new one
xml.field.#match=xml.field.#name;
// delete old one
delete xml.field.#name;
Try setName method: I haven't used it, but the docs says it will work on attributes too.
var xml:XML = <record id="1" name="CustomerInfo">
<field name="id" index="1" type="String"/>
</record>;
xml.#name[0].setName("match");
trace(xml.toXMLString());
xml.field.#name[0].setName("match");
trace(xml.toXMLString());
Update: It works in Firefox e4x javascript, so it should work in ActionScript too. Try this:
var xml:XML = <record id="1" name="CustomerInfo">
<field name="id" index="1" type="String"/>
</record>;
var names:XMLList = xml.descendants("#name");//all `name` attributes
for(var i:Number = 0; i < names.length(); i++)
{
names[i].setName("match");
}
trace(xml.toXMLString());

Resources